Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

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:

 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!

I am creating a basic website for one of my assignments, which must view a database I created in MyPHPAdmin , add and delete a record.

In my View.php on line 55 which is:

while($row = mysqli_fetch_array( $result )).

The following error appears:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\View.php on line 55

Why is this happening and what can I do to resolve this error ?

What I have tried:

Tried using sites similar to this one such as StackOverflow and have not found a solution that answers my question as well as one that I understand as I am a beginner in PHP.


where you are running mysqli_query , add 'or die( mysqli_error($db)'
e.g

$sql = "SELECT * FROM users";
$result = mysqli_query($db, $sql) or die( mysqli_error($db));

$db being the variable holding the connection to db

You have to check the return value of the previous PHP: mysqli::query - Manual[^] call for success. If that fails it returns a boolean false instead of a mysqli_result object.

See the above link on how to check for errors and report them. Printing the error message is useful to know what went wrong (usually an SQL syntax error).

if($result){
while ($row = mysqli_fetch_array($result)) {
echo "result is more then 1" }
}
else{
echo "result is empty"
}

while($row = mysqli_fetch_array( $result ))
it is wrong code
$sql="Here is the SQL query";
$result=mysqli_query($con,$sql);///$con is your MySQL connection code
while($row = mysqli_fetch_array( $result,MYSQLI_ASSOC)){
printe_r($row);
}
/////////////////////////Now all set use it.

i want to print my invoice report but this error sowing . How can I solve ?

Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in
C:\xampp\htdocs\Pharmacy-Management\php\manage_invoice.php:80 Stack trace: #0 C:\xampp\htdocs\PharmacyManagement\php\manage_invoice.php(80): mysqli_fetch_array(false) #1 C:\xampp\htdocs\Pharmacy-Management\php\manage_invoice.php(19):
printInvoice('3') #2 {main} thrown in C:\xampp\htdocs\Pharmacy-Management\php\manage_invoice.php on line 80

mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\pertandingan mewarna\item.php on line 8

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

Hi, I got this error. Please help.

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

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY '".$crieria."' ASC);

$array1 = array();

while($row = mysqli_fetch_array($result_1)){
array_push($array1, "$row[0]->$criteria", "$row[5]->$criteria" , "$row[10]->$criteria");
}

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

Jump to Post

check your spelling is correct or not for '$crieria' near to ORDER BY

Jump to Post

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

Sorry pritaeas.. I haven't see your post.

Jump to Post

@Karthik: No need to be sorry. We saw the same thing, and were probably typing at the same time.

@Jiaxin: See the sticky thread first. It tells you how to trap and find errors.

Jump to Post

Replace your query

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY '".$crieria."' ASC);

with

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC");

Jump to Post

All 19 Replies

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

pritaeas 2,114 ¯\_(ツ)_/¯ Moderator Featured Poster

11 Years Ago

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

Edited 11 Years Ago by pritaeas because: n/a

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

check your spelling is correct or not for '$crieria' near to ORDER BY

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

mysqli_query returns false on failure, indicating something is wrong with your query. See the sticky thread at the top of the PHP forum to find out how you can check for errors (most likely because $criteria is misspelled).

Sorry pritaeas.. I haven't see your post.

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

I typed myself wrongly, but in my code i checked and there is no misspell.

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

pritaeas 2,114 ¯\_(ツ)_/¯ Moderator Featured Poster

11 Years Ago

@Karthik: No need to be sorry. We saw the same thing, and were probably typing at the same time.

@Jiaxin: See the sticky thread first. It tells you how to trap and find errors.

Edited 11 Years Ago by pritaeas because: n/a

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

Replace your query

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY '".$crieria."' ASC);

with

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC");

Edited 11 Years Ago by karthik_ppts because: n/a

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

I replaced it but still have the same error.

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

just echo out the query as

echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

before this line

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC");

copy the printed query and execute it in the SQL section of your phpmyadmin and see the result. it will tell the error if you have error in your query

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

ko ko 97 Practically a Master Poster

11 Years Ago

SELECT $criteria Why dollar sign before 'criteria' after 'SELECT' ?

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

pritaeas 2,114 ¯\_(ツ)_/¯ Moderator Featured Poster

11 Years Ago

Only do that if you want to replace it with a variable. If you think it is wrong, replace it with a *

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

hielo 65 Veteran Poster

11 Years Ago

try:

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC") or die( mysqli_error($link) );

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

try:

$result_1= mysqli_query($link, "SELECT $criteria FROM table ORDER BY $crieria ASC") or die( mysqli_error($link) );

Always let PHP display errors for you in development. Another way described in PHP Manual is:

/* Create table doesn't return a resultset */
if (mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City") === TRUE) {
    printf("Table myCity successfully created.\n");
}

/* Select queries return a resultset */
if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
    printf("Select returned %d rows.\n", mysqli_num_rows($result));

    /* free result set */
    mysqli_free_result($result);
}

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

because i pass in the user input at the $criteria

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

i have already echo out this
echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

but then the result shown are only:
SELECT FROM criteria ORDER BY ASC

and not the real data from database. what can i do to make it echo out all the data in ASC?

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

11 Years Ago

i have already echo out this
echo "SELECT $criteria FROM table ORDER BY $crieria ASC";

but then the result shown are only:
SELECT FROM criteria ORDER BY ASC

and not the real data from database. what can i do to make it echo out all the data in ASC?

Then problem is not in query. Problem is in your input $criteria. Check your input or post your all codes.

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

4 Years Ago

// fetch the record to be updated
if (isset($_GET['edit'])){
    $Id_alat = $_GET['edit'];
    $edit_state = true;
    $rec = mysqli_query($db, "SELECT * FROM alat WHERE Id_alat=$Id_alat");
    $record = mysqli_fetch_array($rec);  -- > its line 8 (wrong code!!)
    $timestamp = $record['timestamp'];
    $klamp = $record['klamp'];
    $Id_alat = $record['Id_alat'];

}

?>

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\php_crud\index.php on line 8

please solve code above it?

Mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in

4 Years Ago

My Code:
include("validation.php");
include("conection.php");
if(isset($_POST["button"]))

$pwde = md5($_POST[password]);

$sql="INSERT INTO administrator (adminid, adminname, password, address, contactno)
VALUES
('$_POST[adminid]','$_POST[adminname]','$pwde','$_POST[address]','$_POST[contactno]')";

if (!mysql_query($sql,$con))

die('Error: ' . mysql_error());

else

  echo "1 record Inserted Successfully...";

$result = mysql_query("SELECT * FROM administrator");
while($row1 = mysql_fetch_array($result))

$adminid = $row1["adminid"]+1;
}

if(isset($_POST["button2"]))

$pwde = md5($_POST[password]);

mysql_query("UPDATE administrator SET adminname='$_POST[adminname]', address='$_POST[address]', contactno='$_POST[contactno]'
WHERE adminid = '$_POST[adminid]'");
echo "Record updated successfully";

if($_GET[view] == "administrator")

$result = mysql_query("SELECT * FROM administrator where adminid='$_GET[slid]'");
while($row1 = mysql_fetch_array($result))

$adminid = $row1["adminid"];
$password = $row1["password"];
$adminname = $row1["adminname"];
$address = $row1["address"];

$contact = $row1["contactno"];

?>

After execution got below warning:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

Please Support....

Reply to this topic

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.

How do you fix warning mysqli_fetch_array () expects parameter 1 to be mysqli_result boolean given?

Solution 1 You have to check the return value of the previous PHP: mysqli::query - Manual[^] call for success. If that fails it returns a boolean false instead of a mysqli_result object. See the above link on how to check for errors and report them.

What is the function of mysqli_fetch_array?

Definition and Usage The fetch_array() / mysqli_fetch_array() function fetches a result row as an associative array, a numeric array, or both. Note: Fieldnames returned from this function are case-sensitive.

What is the difference between Mysqli_fetch_assoc and mysqli_fetch_array?

The major difference between mysqli_fetch_assoc and mysqli_fetch_array is the output format of result data. mysqli_fetch_assoc returns data in an associative array and mysqli_fetch_array returns data in a numeric array and/or in an associative array.

What is mysqli_result?

The mysqli_result class ¶ Represents the result set obtained from a query against the database.