MySql/PHP Query Returning Empty


Here is my code:

$result = mysqli_query($dbconnection, Data::followUser($user_id, $followUser_id));

$result returns empty here.

followUser method in classData

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;

I have verified the function works correctly in echoing out $toast. It is eitherFollow orUnfollow based on condition. I don't think I am handling it right when it comes out?


Here is what I am doing with $result:

if ($result == "Follow") {
            $output["result"] = "Follow";
            echo json_encode($output);
    } elseif ($result == "Unfollow") {
            $output["result"] = "Unfollow";
            echo json_encode($output);



What does this all accomplish? You've basically got:

mysqli_query($dbconnection, 'Unfollow');

which is NOT a valid query in any way.$result is NOT empty. It's a boolean false, indicating a failed query...

People are also looking for solutions to the problem: jquery - Run PHP code after button click but without refreshing page


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.