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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.