Click here to Skip to main content
15,397,224 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 7-Jul-22 0:09am
Comments
Richard MacCutchan 6-Mar-18 4:09am
   
Read the MySQL documentation, where this is explained in detail.

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
   
Comments
Member 14212728 4-Apr-19 3:22am
   
not work for db
Member 14212728 4-Apr-19 3:23am
   
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\school_mca\search.php on line 197


//this one error bro//
techilo genet 13-Jul-21 19:36pm
   
I have get also this problem
Member 14828122 11-May-20 2:25am
   
thanks a lot for this solution sir
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.
   
Comments
techilo genet 13-Jul-21 19:33pm
   
Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #1 ($result) must be of type mysqli_result, bool given in C:\xampp\htdocs\codee\takeuser.php:74 Stack trace: #0 C:\xampp\htdocs\codee\takeuser.php(74): mysqli_fetch_array(false, 1) #1 {main} thrown in C:\xampp\htdocs\codee\takeuser.php on line 74
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
   
Comments
Richard Deeming 27-Jan-22 3:57am
   
Your question is not a "solution" to someone else's question.

And if you'd bothered to read the existing solutions, you would have seen that they also apply to your error.
mysqli_fetch_array() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\pertandingan mewarna\item.php on line 8
   
Comments
CHill60 7-Jul-22 8:27am
   
Simply repeating the error message thrown by your own code is not a solution to this problem

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900