Here we provide you with a simple php shopping cart code, from adding shopping products and purchasing, in the mall development, this function is indispensable, we do not need a database, a txt file is used to operate the user's shopping content. add the product to the shopping cart. the code is as follows: l... here we provide you with a simple php shopping cart code, from adding shopping products and purchasing, in the mall development, this function is indispensable, we do not need a database, a txt file is used to operate the user's shopping content.
Add the product to the shopping cart. the code is as follows:
$ Product) {if (trim ($ prod_id) = trim ($ _ GET [id]) {$ curr_product = $ product ;}} // Register our session // session_register ('cart'); // if (session_is_registered ('cart') echo "registered"; if ($ _ POST [ordered]) {// If they have chosen the product array_push ($ _ SESSION [cart] [products], array (trim ($ _ POST [id]), $ _ POST [quantity]); $ _ SESSION [cart] [num_items] + =$ _ POST [quantity];}?> <? Php if ($ _ POST [ordered]) {?> Added <? Php echo $ curr_product [name];?> To your shopping basket <? Php} else {?> Add <? Php echo $ curr_product [name];?> To your shopping basket <? Php }?>
After being added to the shopping basket, return to the product list page.
Add
To your shopping basket
View the items in the shopping cart. the code is as follows:
0, "products" => array ();} // From site_lib.inc, Loads the $ master_products_list array LoadProducts (); // load the item list?> Demonstrate the basket program for session tracking Welcome to the online store
Items in the current shopping basket
| Product Name |
Product Description |
Unit Price |
Quantity |
|
$ Product) {$ product_id = $ product [0]; $ quantity = $ product [1]; $ total + = $ quantity * (double) $ master_products_list [$ product_id] [price];?>
|
|
|
|
|
| Total: |
RMB:
|
|
Items to be sold in the store
We provide the following products for sale:
| Product Name |
Product Description |
Unit Price |
|
$ Item) {?>
|
|
|
$
|
"> Add to shopping basket |
Modify the number of cart in the following code:
$ _ POST [quantity])? $ _ SESSION [cart] [num_items]-($ old_num-$ _ POST [quantity]): $ _ SESSION [cart] [num_items] + ($ _ POST [quantity]-$ old_num);?> Quantity modification Change quantity:
Change
Return to the product list page.
Function page, the user saves the content in the shopping cart to the txt database, the code is as follows:
$ Name, // name "desc" => $ desc, // description "price" => $ price); // unit price} @ fclose ($ fp) // close the file or die ("failed to close the $ filename File");}?>
It is very simple. we only use four files to implement the shopping cart function with php. well, this is just a simple php shopping cart code that needs to be considered more complicated and better.
Address:
Reprinted at will, but please attach the article address :-)