When I run a SQL query on the id & name from my “author” table in my database, the result generates a list of names. But in my php code, i receive the error message that it is unable to fetch the authors from the database. I know the authors are there so why can’t this code retrieve the names? The code is typed below.
<?php
// Display author list
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
$result = mysqli_query($link, 'SELECT id, name FROM author');
if (!$result)
{
$error = 'Error fetching authors from database!';
include 'error.html.php';
exit();
}
while ($row = mysqli_fetch_array($result))
{
$authors[] = array('id' => $row['id'], 'name' => $row['name']);
}
include 'authors.html.php';
?>