0

Here is my code:

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

$result returns empty here.

followUser method in class 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;
}

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

Supplemental:

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);
    }

1 Answer 1

1

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...

Sign up to request clarification or add additional context in comments.

1 Comment

Wow! What a stupid mistake. I meant: $result = Data::followUser(---); Ive been looking at the screen too long. marking you correct...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.