I have a handler page index.php with the following code
[php]<?php
include_once ‘db_connect.inc.php’;
try {
$result = $pdo->query(‘SELECT id, name from author’);
}
catch (PDOException $e) {
$error = ‘Error fetching authors from database’;
include ‘error,html.php’;
exit();
}
foreach ($results as $row) {
$authors[] = array(‘id’ => $row[‘id’], ‘name’ => $row[‘name’]);
}
include ‘authors.html.php’;
?>[/php]
Then I have a page to display the results
[php]<?php include_once $_SERVER[‘DOCUMENT_ROOT’] .
‘Netbeans/PHP Power/includes/helpers.inc.php’; ?>
Manage Authors
-
<?php foreach ($authors as $author): ?>
-
<?php htmlout($author['name']); ?>
<?php endforeach; ?>
When I look at the page I get the following error:
Notice: Undefined variable: authors in C:\wamp\www\Netbeans\PHP Power\admin\authors\authors.html.php on line 13 (which is the file above on line 13)
I have tried but cannot figure this out. Why is the variable authors undefined. Is it not defined in the handler script and passed to the html page?