O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Shopping Cart

Once you have created a product catalog, as I have now, the actual shopping cart itself can be surprisingly simple. The method I’ve chosen to use in this example is to record the product IDs, prices, and quantities in a session. Knowing these three things will allow the scripts to calculate totals and do everything else required.

These next two examples will provide all the necessary functionality for the shopping cart. The first script, add_cart.php, will add items to the shopping cart. The second, view_cart.php, will both display the contents of the cart and allow the customer to update it.

Adding items

The add_cart.php script will take one argument—the ID of the print being purchased—and will use this to update the cart. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required