I am new to PHP and am reading Kevin Yank’s book “Build your own database driven Web Site using PHP and MySQL”.
His code on page 202 Managing Authors is as follows:
<?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 $_SERVER['DOCUMENT_ROOT'] . 'includes/error.html.php';
exit();
}
while ($row = mysqli_fetch_array($result))
{
$authors[] = array('id' => $row['id'], 'name' => $row['name']);
}
include authors.html.php;
?>
When I execute this code I get the following:
Warning: include(C:/xampp/htdocsincludes/db.inc.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 3
Warning: include(): Failed opening 'C:/xampp/htdocsincludes/db.inc.php' for inclusion (include_path='C:\xampp\htdocs\includes') in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 3
Notice: Undefined variable: link in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 4
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 4
Warning: include(C:/xampp/htdocsincludes/error.html.php): failed to open stream: No such file or directory in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 8
Warning: include(): Failed opening 'C:/xampp/htdocsincludes/error.html.php' for inclusion (include_path='C:\xampp\htdocs\includes') in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 8
I have checked the permissions and I am lost! Can someone help me?