-
- //Product category page
- session_start();//Open session environment
- //Determine whether the user has clicked the "Add to Shopping Cart" button
- if(isset($_POST[' cart'])){
- //Assign value in a loop
-
- foreach($_POST['cart'] as $value){
- //If the product is in the shopping cart
- //Condition:
- //Click "Put" "Add to shopping cart"---array $_SESSION['cart'];
- //Determine which product----Determine whether the name of the product appears in the array
- //array_key_exists(subscript, array);
- if(isset($_SESSION['cart'])&& array_key_exists($value,$_SESSION['cart'])){
- $_SESSION['cart'][$value]++;
- }else{
-
- //If the product is not in the shopping cart
- $_SESSION['cart'][$value]=1;
- }
- }
- }
- ?>
-
- Online Mall_php Shopping Cart-bbs.it-home.org
-
Online Mall
- Daily Necessities
- Household appliances
- Stationary supplies
- < a href="carlist.php">View cart
- Clear cart
Copy code 2. carlist.php displays the items in the shopping cart
3. File cardel.php to clear the shopping cart
-
-
- session_start();//Open session environment
//Clear the shopping cart
- unset($_SESSION['cart'] );
- ?>
- alert("Cleared successfully");
- location.href="car.php";
-
-
Copy code
The above code implements the common functions of a shopping cart, displaying product classification and information, processing of products in the shopping cart, etc. I hope to be helpful.
|