0% found this document useful (0 votes)
577 views

PHP - Mysqli - Fetch - Array Expects Parameter 1 To Be Mysqli - Result, Boolean Given in - Stack Overflow

The document discusses a PHP error where mysqli_fetch_array() expects the first parameter to be a mysqli_result object but is receiving a boolean. The error occurs when querying a MySQL database on localhost but not on a live server. The issue is likely that the query is failing and returning false instead of a result set. Adding error handling after mysqli_query() can identify why the query is failing. Using prepared statements helps prevent SQL injection vulnerabilities.

Uploaded by

Mirza Malaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
577 views

PHP - Mysqli - Fetch - Array Expects Parameter 1 To Be Mysqli - Result, Boolean Given in - Stack Overflow

The document discusses a PHP error where mysqli_fetch_array() expects the first parameter to be a mysqli_result object but is receiving a boolean. The error occurs when querying a MySQL database on localhost but not on a live server. The issue is likely that the query is failing and returning false instead of a result set. Adding error handling after mysqli_query() can identify why the query is failing. Using prepared statements helps prevent SQL injection vulnerabilities.

Uploaded by

Mirza Malaya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

4/12/2018 php - mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in - Stack Overflow

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

This question already has an answer here:


mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource 31 answers

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:

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

php mysql facebook boolean

edited Oct 7 '17 at 1:17 asked Mar 15 '13 at 18:43


castis Mats de Swart
6,509 2 31 50 198 1 2 8

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

That query is failing and returning false .

put this after mysqli_query() to see whats going on.

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

edited Oct 7 '17 at 1:15 answered Mar 15 '13 at 18:52


castis
6,509 2 31 50

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

You might also like