Php shopping cart code

Source: Internet
Author: User
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) {$ product_id = $ product [0]; $ quantity = $ product [1]; $ total + = $ quantity * (double) $ master_products_list [$ product_id] [price];?>
Product Name Product Description Unit Price Quantity
Total: RMB:  


Items to be sold in the store
We provide the following products for sale:
$ Item) {?>
Product Name Product Description Unit Price
$ "> 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 :-)

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.