php – Call to a member function fetch_assoc() on boolean in

php – Call to a member function fetch_assoc() on boolean in

The query method can return false instead of a result set in case there is an error. That is why you get the error on the fetch_assoc method call, which obviously does not exist when $result is false.

This means you have an error in your SELECT statement. To get that error displayed, do this:

 $result = $conn->query($sql) or die($conn->error);

Most probably you have a wrong spelling for the table name or a column name. Maybe when moving to the host you did not create that table correctly, and made a spelling mistake there.

You should in fact see the same error when executing the same query via phpAdmin.

Also, replace this line:

while(($row = $result->fetch_assoc()) !== null){

with just:

while($row = $result->fetch_assoc()) {

You could also add this for debugging:

echo number of rows:  . $result->num_rows;

This error happen usually when tables in the query doesnt exist. Just check the tables spelling in the query, and it will work.

php – Call to a member function fetch_assoc() on boolean in

OK, i just fixed this error.

This happens when there is an error in query or table doesnt exist.

Try debugging the query buy running it directly on phpmyadmin to confirm the validity of the mysql Query

Leave a Reply

Your email address will not be published.