Php shopping cart implementation code (1/2)

Source: Internet
Author: User
Tags mysql tutorial

With regard to shopping cart, this is a lot of e-commerce use, the user selects their own products need to be saved, and finally go to the cashier, this is like our real-life supermarket, so now I want to write a simple php shopping cart instance code. For more details, we only need to step by step, and it will be OK if the processing is complete.

Php tutorial shopping cart implementation code

With regard to shopping cart, this is a lot of e-commerce use, the user selects their own products need to be saved, and finally go to the cashier, this is like our real-life supermarket, so now I want to write a simple php shopping cart instance code. For more details, we only need to step by step, and it will be OK if the processing is complete.

Some shopping cart will use PHP files
Main. php display product
Additem. php add items to the shopping cart
Cearcart. php Delete the item in the shopping cart
Shoppingcart. php operation class
 
User Database tutorials include:

Inventory
Create table inventory (
Product tinytext not null,
Quantity tinytext not null,
Id int (4) default '0' not null auto_increment,
Description tinytext not null,
Price float (10, 2) default '0. 00' not null,
Category char (1) default ''not null,
Key id (id ),
Primary key (id ),
Key price (price)
);
Insert into inventory values ('hard disk ', '5', '1', '80 gb', '123', '1 ');
Insert into inventory values ('cpu ', '12', '2', 'p4-2.4g', '123', '1 ');
Insert into inventory values ('dvd-rom ', '7', '3', '12x', '123', '1 ');
Insert into inventory values ('motherboard www.bkjia.com ', '3', '4', 'asus', '123', '2 ');
Insert into inventory values ('dashboard ', '6', '5', '64m', '123', '1 ');
Insert into inventory values ('recorders ', '4', '6', '52w', '123', '1 ');
 
Shopping
Create table shopping (
Session tinytext not null,
Product tinytext not null,
Quantity tinytext not null,
Card tinytext not null,
Id int (4) default '0' not null auto_increment,
Key id (id ),
Primary key (id)
);
Shopper
 
Create database shopper;
Use shopper;
Create table shopping (
Session tinytext not null,
Product tinytext not null,
Quantity tinytext not null,
Card tinytext not null,
Id int (4) default '0' not null auto_increment,
Key id (id ),
Primary key (id)
);
Create table inventory (
Product tinytext not null,
Quantity tinytext not null,
Id int (4) default '0' not null auto_increment,
Description tinytext not null,
Price float (10, 2) default '0. 00' not null,
Category char (1) default ''not null,
Key id (id ),
Primary key (id ),
Key price (price)
);
Insert into inventory values ('hard disk ', '5', '1', '80 gb', '123', '1 ');
Insert into inventory values ('cpu ', '12', '2', 'p4-2.4g', '123', '1 ');
Insert into inventory values ('dvd-rom ', '7', '3', '12x', '123', '1 ');
Insert into inventory values ('motherboard php100.com ', '3', '4', 'asus', '123', '2 ');
Insert into inventory values ('dashboard ', '6', '5', '64m', '123', '1 ');
Insert into inventory values ('recorders ', '4', '6', '52w', '123', '1 ');

*/

// Main. php displays all items in the shopping cart

Include ("shoppingcart. php ");
$ Cart = new cart;
$ Table = "shopping ";

/* Query and display information in all inventory tables */
$ Query = "select * from inventory ";
$ Invresult = mysql tutorial _ query ($ query );
If (! ($ Invresult )){
Echo "query failed <br> ";
Exit;
}
Echo "the following products are available for subscription ";
Echo "<table border = 0> ";
Echo "<tr> <td bgcolor = # aaccff> product no. </td> <td bgcolor = # aaccff> product name </td> <td bgcolor = # aaccff> unit price </td> ";
Echo "<td bgcolor = # aaccff> remaining quantity </td> <td bgcolor = # aaccff> product description </td> <td bgcolor = # aaccff> in the shopping cart </td> </tr> ";
While ($ row_inventory = mysql_fetch_object ($ invresult )){
Echo "<tr> <td bgcolor = # aaccff>". $ row_inventory-> id. "</td> ";
Echo "<td bgcolor = # aaccff>". $ row_inventory-> product. "</td> ";
Echo "<td bgcolor = # aaccff>". $ row_inventory-> price. "</td> ";
Echo "<td bgcolor = # aaccff>". $ row_inventory-> quantity. "</td> ";
Echo "<td bgcolor = # aaccff>". $ row_inventory-> description. "</td> ";
Echo "<td bgcolor = # aaccff> <a href = 'additem. php? Product = ". $ row_inventory-> product. "'> </a> </td> </tr> ";
}
Echo "</table> ";
Echo "<br> quantity of products in the shopping cart:". $ cart-> quant_items ($ table, $ session );
Echo "<br> <a href = 'clearcart. php'> </a> clear the shopping cart ";

1 2

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.