The Catalog

First let’s take a look at the catalog script. It serves two purposes—it lists the products on the screen, and it adds selected products to the shopping cart. Each item in the cart has its own form, which the user can submit to add an item to the cart. The form fields are passed back to the catalog.pl script through the query string.

Like many of the scripts presented in this book, it decides what to do based on the parameters it receives in the query string. If a product ID is passed to the script, it retrieves the user’s session ID or assigns a new one, and attempts to add that product to her cart. If no product ID is passed to the script, it just displays the product listing without altering the contents of the user’s cart. The ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.