The Shopping Cart Script

The cart.pl program has two purposes—to list the contents of the user’s shopping cart and to remove items from the cart. When I kept everything in text files, this program was pretty complex because it had to correlate products listed in the cart.txt file with product information stored in the products.txt file. In this case, I use a single query to fetch the contents of the cart and the product information for each of the products in the cart at once. A delete statement is used to remove items from the user’s shopping cart. All of the database connection code in this script is identical to that in catalog.pl. In other words, I included the db_connect and db_cleanup subroutines, imported the DBI module, and set the variables ...

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.