Monday, November 29, 2010

PHP code for a simple shopping cart

While researching about web site shopping cart, I was curious how difficult building a shopping cart would be. I would like to try to see if I could implement this one my Interactive Tutorial website but gozips doesn't allow php code to be implemented. I came across this site that gives a very easy tutorial on how to make a php shopping cart.

The shopping cart uses the server-side language PHP and a MySQL database. Some of the code can be confusing to understand but if you look at it carefully it can be under stood. I have never coded in PHP before but I can kind of understand this segment of code setting up the database


  1. CREATE TABLE books (
  2. id int(6) unsigned NOT NULL auto_increment,
  3. title varchar(100) NOT NULL default '',
  4. author varchar(100) NOT NULL default '',
  5. price decimal(3,2) NOT NULL default '0.00',
  6. PRIMARY KEY (id)
  7. ) TYPE=MyISAM;
The id will be an integer with the maximum of 1 million books. I think the varchar(100) give the title and the author a 100 character maximum. The price decimal(3,2) makes the price a decimal with 2 decimal places and the maximum be $999.

This shopping cart will also give you a running total of the price and of how many items are in the shopping cart. It show you how to remove, update and add more items to your shopping cart.


No comments:

Post a Comment