Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit f9076eb6 authored by 65160260's avatar 65160260
Browse files

Edit cart.php

parent 3de7a29e
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ if (!isset($_SESSION['user_id'])) { ...@@ -8,7 +8,7 @@ if (!isset($_SESSION['user_id'])) {
die("กรุณาเข้าสู่ระบบก่อน"); die("กรุณาเข้าสู่ระบบก่อน");
} }
//เพิ่มสินค้าเข้า `cart` //เพิ่มสินค้าเข้า cart
if (isset($_GET['add'])) { if (isset($_GET['add'])) {
$stmt = $conn->prepare(" $stmt = $conn->prepare("
INSERT INTO cart (id, users_id, products_id, qty) INSERT INTO cart (id, users_id, products_id, qty)
...@@ -20,7 +20,7 @@ if (isset($_GET['add'])) { ...@@ -20,7 +20,7 @@ if (isset($_GET['add'])) {
exit; exit;
} }
//อัปเดตจำนวนสินค้า //อัปเดตจำนวนสินค้า
if (isset($_GET['update']) && isset($_GET['qty'])) { if (isset($_GET['update']) && isset($_GET['qty'])) {
$qty = max(1, intval($_GET['qty'])); // ป้องกันค่าติดลบ $qty = max(1, intval($_GET['qty'])); // ป้องกันค่าติดลบ
$stmt = $conn->prepare("UPDATE cart SET qty = ? WHERE users_id = ? AND products_id = ?"); $stmt = $conn->prepare("UPDATE cart SET qty = ? WHERE users_id = ? AND products_id = ?");
...@@ -29,7 +29,7 @@ if (isset($_GET['update']) && isset($_GET['qty'])) { ...@@ -29,7 +29,7 @@ if (isset($_GET['update']) && isset($_GET['qty'])) {
exit; exit;
} }
//ลบสินค้าออกจาก `cart` //ลบสินค้าออกจาก cart
if (isset($_GET['remove'])) { if (isset($_GET['remove'])) {
$stmt = $conn->prepare("DELETE FROM cart WHERE users_id = ? AND products_id = ?"); $stmt = $conn->prepare("DELETE FROM cart WHERE users_id = ? AND products_id = ?");
$stmt->execute([$_SESSION['user_id'], $_GET['remove']]); $stmt->execute([$_SESSION['user_id'], $_GET['remove']]);
...@@ -37,7 +37,7 @@ if (isset($_GET['remove'])) { ...@@ -37,7 +37,7 @@ if (isset($_GET['remove'])) {
exit; exit;
} }
//ดึงข้อมูลจาก `cart` และ `products` //ดึงข้อมูลจาก cart และ products
$stmt = $conn->prepare(" $stmt = $conn->prepare("
SELECT cart.*, products.name, products.price SELECT cart.*, products.name, products.price
FROM cart FROM cart
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment