Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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 22-Feb-23 23:01pm
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
 
Share this answer
 
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).
 
Share this answer
 
if($result){
while ($row = mysqli_fetch_array($result)) {
echo "result is more then 1" }
}
else{
echo "result is empty"
}
 
Share this answer
 
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.
 
Share this answer
 
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
There is error in the SQL Query, May be you have used a field in the query that is not there in the database table
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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