我的 PHP 类有问题,当用户想要关注另一个用户时,会调用 follow 方法,而当用户想要停止关注时,delete_follow
会调用:
class Follow {
protected static $table_name = "interests";
public function follow() {
global $dbh;
$sql = "INSERT INTO ".self::$table_name." (company_id,user_id,likedate) VALUES (:company_id,:user_id,NOW())";
$follow = $dbh->prepare($sql);
$follow->bindParam(':user_id',$_SESSION['user_id']);
$follow->bindParam(':company_id',$_GET['company']);
if($follow->execute() == true){
header("Location: profile.php?company=".$_GET['company']."");
exit;
} else {
header("Location: error.php");
exit;
}
}
public function delete_follow() {
global $dbh;
$sql = "DELETE FROM ".self::$table_name." WHERE company_id = :company_id AND user_id = :user_id LIMIT 1";
$delete_follow = $dbh->prepare($sql);
$delete_follow->bindParam(':user_id',$_SESSION['user_id']);
$delete_follow->bindParam(':company_id',$_GET['company']);
if($delete_follow->execute() == true) {
header("Location: profile.php?company=".$_GET['company']."");
exit;
} else {
header("Location: error.php");
exit;
}
}
}
我的问题是,当调用 delete_follow 方法时,它实际上调用了 follow 方法,我不知道发生了什么。
以下是以下按钮的代码:
if(isset($_POST['follow'])) {
$follows = new Follow();
$follows->follow();
}
if(isset($_POST['delete_follow'])) {
$follows = new Follow();
$follows->delete_follow();
}
请帮忙。