PHP - Mysqli - Fetch - Array Expects Parameter 1 To Be Mysqli - Result, Boolean Given in - Stack Overflow
PHP - Mysqli - Fetch - Array Expects Parameter 1 To Be Mysqli - Result, Boolean Given in - Stack Overflow
I'm have some trouble checking if an FB User_id already exists in my db (if it doesn't it should then accept user as a new one and else just load the canvas
app). I ran it on my hosting server and there was no problem, but on my localhost it gives me the following error:
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 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, User won't be able to load app on failure inserting to 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!
marked as duplicate by John Conde, Tomasz Kowalczyk, hjpotter92, spajce, DarkAjax Mar 15 '13 at 23:27
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2 You 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. – Mike Brant Mar 15 '13 at
18:45
1 Please, please use the mysqli prepared statement feature to properly escape your SQL queries. – tadman Mar 15 '13 at 18:59
1 Answer
if (!$check1_res) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
https://stackoverflow.com/questions/15439919/mysqli-fetch-array-expects-parameter-1-to-be-mysqli-result-boolean-given-in?utm_medium=organic&utm_source=goog
4/12/2018 php - mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in - Stack Overflow
for more information:
http://www.php.net/manual/en/mysqli.error.php
Join Stack Overflow to learn, share knowledge, and build your career. Email Sign Up OR SIGN IN WITH Google Facebook
https://stackoverflow.com/questions/15439919/mysqli-fetch-array-expects-parameter-1-to-be-mysqli-result-boolean-given-in?utm_medium=organic&utm_source=goog