-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove_from_cart.php
More file actions
33 lines (27 loc) · 832 Bytes
/
Copy pathremove_from_cart.php
File metadata and controls
33 lines (27 loc) · 832 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
30
31
32
33
<?php
session_start();
require 'db.php';
if (!isset($_SESSION['logged_in']) || $_SESSION['Category'] != 0) {
$_SESSION['message'] = "Please login as a buyer to access the cart!";
header("Location: Login/error.php");
exit();
}
if (isset($_GET['pid'])) {
$pid = (int)$_GET['pid'];
$buyer_id = $_SESSION['id'];
// Remove item from cart
$sql = "DELETE FROM mycart WHERE bid = ? AND pid = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ii", $buyer_id, $pid);
if ($stmt->execute()) {
$_SESSION['message'] = "Item removed from cart successfully!";
} else {
$_SESSION['message'] = "Error removing item from cart: " . $conn->error;
}
$stmt->close();
} else {
$_SESSION['message'] = "Invalid request!";
}
header("Location: cart.php");
exit();
?>