我对此代码存在一些问题:
function previously_liked($id) {
if (isset($_SESSION['user_login'])) {
$user = $_SESSION["user_login"];
}
else {
$user = "";
}
$connection = new mysqli($host, $username, $password, $database);
$id = $connection->real_escape_string($id);
$query = $connection->query("SELECT `user_id` AS `count` FROM `likes` WHERE `id` = '$id' AND `user_id` = '".$connection->escape_string($user)."'");
if ($query->fetch_object()->count == $user) {
return true;
}
else {
return false;
}
}
应该检查用户是否已经喜欢帖子,如果用户已经喜欢它,则返回true
,如果没有,则返回false
。
问题是,当用户确实喜欢某事时,它不会返回true。