Manage Authors

On page 203 of Kevin Yank;s book is:

<?php include_once $_Server['Document_Root'] . '/includes/helpers.inc.php'; ?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Manage Authors</title>
    </head>
    <body>
        <h1>Manage Authors</h1>
        <p><a href="?add">Add new author</a></p>
        <ul>
            <?php foreach ($authors as $author); ?>
            <li>
                <form action="" method="post">
                    <div>
                        <?php htmlout($author['name']); ?>
                        <input type="hidden" name="id" value="<?php echo $author['id']; ?>" />
                        <input type="submit" name="action" value="Edit" />
                        <input type="submit" name="action" value="Delete" />
                    </div>
                </form>
            </li>
         <?php endforeach; ?>
        </ul>
        <p><a href="..">Return to JMS home</a></p> 
    </body>
</html>

When executed I get:
Notice: Use of undefined constant authors - assumed ‘authors’ in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 15

Notice: Use of undefined constant html - assumed ‘html’ in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 15

Notice: Use of undefined constant php - assumed ‘php’ in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 15

Warning: include(authorshtmlphp): failed to open stream: No such file or directory in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 15

Warning: include(): Failed opening ‘authorshtmlphp’ for inclusion (include_path=‘C:\xampp\htdocs\includes’) in C:\xampp\htdocs\Jokes\Admin\Authors\index.php on line 15

Netbeans also tells me that the “endforeach” is unexpected?

Generally, when you get “undefined constant - assumed” error messages it’s because of missing quotation marks.

The “failed to open - no such” error looks to be because of missing periods between name and extension,

The “unexpected” error message is most likely due to unpaired curly braces.

1 Like

I now get:
Parse error: syntax error, unexpected ‘endforeach’ (T_ENDFOREACH) in C:\xampp\htdocs\Jokes\Admin\Authors\authors.html.php on line 23

I know nothing about php so I have no idea where the curly braces would go.

This should be <?php foreach ($authors as $author) : ?>.

Notice the colon : instead of the semi-colon ; at the end.

2 Likes

That works fine - I guess I should pay closer attention - thank you

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.