<html>
<table>
<tr>
<th>Id</th>
<th>Username</th>
<th>Result</th>
</tr>
<?php
$conn = new mysqli("localhost", "root", "", "roboit");
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, username, result FROM result";
$result = $conn->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"]. "</td><td>" . $row["username"] . "</td><td>". $row["result"]. "
</td></tr>";
}
echo "</table>";
} else { echo "0 results"; }
$conn->close();
?>
</table>
</html>
This is the code. I've checked it from different sources (starting from Indian programmers and ending by W3Schools) and they are very similar or even absolutely equal. But it tells me that $result is a non-object. What to do?
I couldn't find the answer on the similar questions too. (here I mean)