-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_cart.php
More file actions
29 lines (24 loc) · 794 Bytes
/
Copy pathupdate_cart.php
File metadata and controls
29 lines (24 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
session_start();
require 'db.php';
if (!isset($_SESSION['logged_in']) || $_SESSION['Category'] != 0) {
die('Unauthorized access');
}
if (isset($_POST['pid']) && isset($_POST['quantity'])) {
$pid = (int)$_POST['pid'];
$quantity = (int)$_POST['quantity'];
$buyer_id = $_SESSION['id'];
// Update quantity in cart
$sql = "UPDATE mycart SET quantity = ? WHERE bid = ? AND pid = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("iii", $quantity, $buyer_id, $pid);
if ($stmt->execute()) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'error' => $conn->error]);
}
$stmt->close();
} else {
echo json_encode(['success' => false, 'error' => 'Missing parameters']);
}
?>