Php shopping cart function implementation code (getting started example)
- // Product category page
- Session_start (); // enable the session environment
- // Determine whether the user has clicked the "add to shopping cart" button
- If (isset ($ _ POST ['cart']) {
- // Value assignment in cyclic mode
- Foreach ($ _ POST ['cart'] as $ value ){
- // If this item exists in the shopping cart
- // Condition:
- // Click "Add to shopping cart". an array $ _ SESSION ['cart'] exists.
- // Determine the product ---- determine whether the product name has appeared in the array
- // Array_key_exists (subscript, array );
- If (isset ($ _ SESSION ['cart']) & array_key_exists ($ value, $ _ SESSION ['cart']) {
- $ _ SESSION ['cart'] [$ value] ++;
- } Else {
- // If this item is not found in the shopping cart
- $ _ SESSION ['cart'] [$ value] = 1;
- }
- }
- }
- ?>
- Online shopping mall _ php shopping cart -bbs.it-home.org
- Online Store
- Daily necessities
- Household appliances
- Stationery
- View Shopping Cart
- Clear shopping cart
2. carlist. php shows the items in the shopping cart.
-
// Display the items in the shopping cart (item name, item quantity)
- Session_start ();
- Echo "the items you have selected include:
";
- Echo "";
- Echo "back to homepage ";
- ?>
-
3. clear the cardel. php file to the shopping cart.
-
Session_start (); // enable the session environment
-
// Clear the shopping cart
- Unset ($ _ SESSION ['cart']);
- ?>
|