这是我的代码:
$result = mysqli_query($dbconnection, Data::followUser($user_id, $followUser_id));
$result
在此处返回空白。
followUser
中的 Data
方法
public static function followUser($user_id, $followUser_id) {
global $database;
$query = "
SELECT *
FROM profile_follow
WHERE user_id = '{$user_id}'
AND follow_id = '{$followUser_id}';";
$result = $database -> query($query);
$num = mysqli_num_rows($result);
if ($num < 1) {
$toast = "Follow";
$query = "
INSERT INTO profile_follow (user_id, follow_id)
VALUES ('{$user_id}', '{$followUser_id}');";
$result = $database -> query($query);
} elseif ($num > 0) {
$toast = "Unfollow";
$query = "
DELETE FROM profile_follow
WHERE user_id = '{$user_id}'
AND follow_id = '{$followUser_id}';";
$result = $database -> query($query);
}
return $toast;
}
我已经验证了该函数在回显$ toast时正常工作。根据条件,它是Follow
或Unfollow
。我不认为我出来的时候正在处理它?</ p>
补充:
以下是我用$ result做的事情:
if ($result == "Follow") {
$output["result"] = "Follow";
echo json_encode($output);
} elseif ($result == "Unfollow") {
$output["result"] = "Unfollow";
echo json_encode($output);
}
答案 0 :(得分:1)
这一切都完成了什么?你基本上得到了:
mysqli_query($dbconnection, 'Unfollow');
这不是任何有效的查询。 $result
不是空的。这是一个布尔值false,表示查询失败......