Amongst what I’m sure are a plethora of other problems, the $result variable isn’t being recognized
getting a
Fatal error: Call to a member function fetch_assoc() on a non-object
and I’m not sure why. Any help would be appreciated. Here’s the code:
<html>
<body>
<?PHP
$db = new mysqli('localhost', 'root', '', 'edumacation');
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$result = <<<SQL
SELECT *
FROM `student`
WHERE `id` = 1
SQL;
while($row =
$result->fetch_assoc()){
echo "<table border='1'><tr><th>Name</th><th>Grade</th><th>Favorite Teacher</th><th>Date Enrolled</th></tr>";
echo "<tr><td>" . $row['first_name'] . "</td><td>" . $row['grade'] . "</td><td>" . $row['fav_teacher'] . "</td></tr>" . $row['enrolled'] . "<br />";
echo "</table>";
}
?>
</body>
</html>
Well, you’re not actually executing the query, just setting a string to what you want the SQL to be. Something like this would work better;