0

So, I made a while statement to display all of my sql data, here's my code:

while($row = $result->fetch_assoc()){
        echo "<tr>
        <td>$row[ID]</td>
        <td>$row[USERNAME]</td>
        <td>$row[PASSWORD]</td>
        <td>$row[EMAIL]</td>
        </tr>";
}

Don't worry about the table and /table as i have put it somewhere else. This code was working with MySQL, but now that i changed the code to work with MySQLI, it is no longer working. My databases are set up correctly, but i get this error code on my webpage now: Fatal error: Call to a member function fetch_assoc() on boolean in http://xxxxxxxxx on line 66 (which is the while line)

Please explain to me why this is not working in the simplest way possible. I am still a beginner at PHP and MySQLI. Also, I saw another article on this, but I have no understanding on what is going on there.

EDIT: FULL PHP CODE -

<?php
    //MYSQLI LOGIN DETAILS
    $servername = "xxx";
    $username = "xxx";
    $password = "xxx";
    //MYSQLI CREATE CONNECTION
    $constatus = new mysqli($servername, $username, $password);
    //MYSQLI CHECK CONNECTION
    if ($constatus->connect_error) {
        die("Connection failed: " . $constatus->connect_error);
    }
    //SELECT TABLE
    $sql = "SELECT * FROM userdata";
    $result = $constatus->query($sql);
    echo "<table border='1'>
        <tr>
        <td>ID</td>
        <td>USERNAME</td>
        <td>PASSWORD</td>
        <td>EMAIL</td>
        </tr>";
    while($row = $result->fetch_assoc()){
        echo "<tr>
        <td>$row[ID]</td>
        <td>$row[USERNAME]</td>
        <td>$row[PASSWORD]</td>
        <td>$row[EMAIL]</td>
        </tr>";
    }
    echo "</table>";
?>
George Jones
  • 245
  • 2
  • 11

0 Answers0