0

Please I need help with this error, gurus in the house.

Its my first php project and the error is giving me a bad day.

It keeps on showing me this;

Fatal error: Call to a member function fetch_array() on boolean in C:\xampp\htdocs\myfirstfile.php on line 22

 <?php 

 $query = "SELECT * FROM chat ORDER BY id"; 

 $run = $con->query($query); 

/*22*/ while($row = $run->fetch_array()) :

 ?>

 <div id="chat_data"> 
 <span style="color:green;"><?php echo $row['Nickname']; ?> :</span> 
 <span style="color:brown;"><?php echo $row['text']; ?>:</span> 

 </div>

 <?php
      endwhile;
   ?> 
Dharman
  • 30,962
  • 25
  • 85
  • 135
Aqueous
  • 31
  • 1
  • 4

2 Answers2

4

The result of your query was false (which means - something went wrong there) so what you are actually doing is false->fetch_array(), which doesn't really makes any sense.

If you add some error checking, for example:

$run = $con->query($query) or die("Last error: {$con->error}\n");

You can see what went wrong there and fix it.

Dekel
  • 60,707
  • 10
  • 101
  • 129
-1

change your fetch statement to

$row = $con->fetch_array($run)
Bhavik
  • 495
  • 2
  • 10