Specifications

LISTING 25.18 insert_book.phpThis Script Validates the New Book Data and Puts It
into the Database
<?
// include function files for this application
require_once(“book_sc_fns.php”);
session_start();
do_html_header(“Adding a book”);
if (check_admin_user())
{
if (filled_out($HTTP_POST_VARS))
{
if(insert_book($isbn, $title, $author, $catid, $price, $description))
echo “Book ‘$title’ was added to the database.<br>”;
else
echo “Book ‘$title’ could not be added to the database.<br>”;
}
else
echo “You have not filled out the form. Please try again.”;
do_html_url(“admin.php”, “Back to administration menu”);
}
else
echo “You are not authorised to view this page.”;
do_html_footer();
?>
You can see that this script calls the function insert_book(). This function and the others
used by the administrative scripts can be found in the function library admin_fns.php.
In addition to adding new categories and books, the administrative user can edit and delete
these items. We have implemented this by reusing as much code as possible. When the admin-
istrator clicks the Go to main site link in the administration menu, she will go to the category
index at index.php and can navigate the site in the same way as a regular user, using the same
scripts.
There is a difference in the administrative navigation, however: Administrators will see differ-
ent options based on the fact that they have the registered session variable $admin_user. For
example, if we look at the show_book.php page that we were looking at previously in the
chapter, we will see some different menu options. Look at Figure 25.14.
Building a Shopping Cart
C
HAPTER 25
25
B
UILDING A
SHOPPING CART
579
31 7842 CH25 3/6/01 3:39 PM Page 579