Specifications

// set url for “continue button”
$target = “index.php”;
if($book[“catid”])
{
$target = “show_cat.php?catid=”.$book[“catid”];
}
// if logged in as admin, show edit book links
if( check_admin_user() )
{
display_button(“edit_book_form.php?isbn=$isbn”, “edit-item”, “Edit Item”);
display_button(“admin.php”, “admin-menu”, “Admin Menu”);
display_button($target, “continue”, “Continue”);
}
else
{
display_button(“show_cart.php?new=$isbn”, “add-to-cart”,
“Add “.$book[“title”].” To My Shopping Cart”);
display_button($target, “continue-shopping”, “Continue Shopping”);
}
do_html_footer();
?>
Again with this script, we are doing very similar things as in the previous two pages. We begin
by starting the session, and then use
$book = get_book_details($isbn);
to get the book information out of the database, and
display_book_details($book);
to output the data in HTML.
One thing to note here is that
display_book_details() looks for an image file for the book as
images/$isbn.jpg. If this file does not exist, no image will be displayed.
The remainder of the script sets up navigation. A normal user will have the choices Continue
Shopping, which will take her back to the category page, and Add to Cart, which will add the
book to her shopping cart. If a user is logged in as an administer, she will get some different
options, which well look at in the section on administration.
That completes the basics of the catalog system. Lets go ahead and look at the code for the
shopping cart functionality.
Building Practical PHP and MySQL Projects
P
ART V
556
LISTING 25.8 Continued
31 7842 CH25 3/6/01 3:38 PM Page 556