Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)
edited by

I am having some difficulty checking if a Facebook User_id already exists in my database (if it does not it should then accept the user as a new one and else simply load the canvas application). I was running it on my hosting server and there was no problem, but on my localhost, it gives me the below error:

mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in

Here is my code:

<?

$fb_id = $user_profile['id'];

$locale = $user_profile['locale'];

if ($locale == "nl_NL") {

    // Checking User Data @ WT-Database

    $check1_task = "SELECT * FROM `users` WHERE `fb_id` = " . $fb_id . " LIMIT 0, 30 ";

    $check1_res = mysqli_query($con, $check1_task);

    $checken2 = mysqli_fetch_array($check1_res);

    print $checken2;

    // If the user does not exist @ WT-Database -> insert

    if (!($checken2)) {

        $add = "INSERT INTO users (fb_id, full_name, first_name, last_name, email) VALUES ('$fb_id', '$full_name', '$first_name', '$last_name', '$email')";

        mysqli_query($con, $add);

    }

    // Double-check, the user won't be able to load the app on failure inserting to the database

    if (!($checken2)) {

        echo "Excuse us " . $first_name . ". Something went terribly wrong! Please try again later!";

        exit;

    }

} else {

    include ('sorrylocale.html');

    exit;

}

I have read, this has something to do with my query being wrong, but it has worked on my hosting provider so that can not be it.

1 Answer

0 votes
by (12.7k points)
edited by

The query is failing and it's returning false.

Place this after mysqli_query() to see what's going on.

if (!$check1_res) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

For more information, check it here.

Want to get certified in SQL! Learn SQL from top SQL experts and excel in your career with Intellipaat’s SQL Certification training program.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...