mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
457,453
The query given to mysqli_query()
is failing and returning false
.
Put this after mysqli_query()
to see what's going on.
if (!$check1_res) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
For more information:
http://www.php.net/manual/en/mysqli.error.php
Related videos on Youtube
Author by
Mats de Swart
Updated on April 09, 2021Comments
-
Mats de Swart about 3 years
I'm have some trouble checking if a Facebook User_id already exists in my database (if it doesn't it should then accept the user as a new one and else just load the canvas application). I ran it on my hosting server and there was no problem, but on my localhost it gives me the following error:
mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in
Here's 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've read it has something to do with my query being wrong, but it has worked on my hosting provider so that can't be it!
-
Mike Brant over 11 yearsYou need to add error handling for your queries so you can find out exactly why it is failing. You also have a significant SQL injection vulnerability.
-
tadman over 11 yearsPlease, please use the
mysqli
prepared statement feature to properly escape your SQL queries.
-
-
Felipe the Sheepy over 4 yearswhere do I define $check1_res?
-
castis over 4 yearsin OPs example,
$check1_res
is the result of amysqli_query()
call.