Click here to Skip to main content
14,732,936 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.
Updated 4-Sep-20 1:08am
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)'
$sql = "SELECT * FROM users";
$result = mysqli_query($db, $sql) or die( mysqli_error($db));

$db being the variable holding the connection to db
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//
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).
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)){
/////////////////////////Now all set use it.

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