-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeletecart.php
43 lines (36 loc) · 1.24 KB
/
Deletecart.php
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
34
35
36
37
38
39
40
41
42
43
<?php
header("Access-Control-Allow-Origin: *"); // Allow any origin (you can restrict this if needed)
header("Access-Control-Allow-Methods: POST"); // Allow POST requests
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With");
// Include the database connection
include 'Conx.php';
// Get the input data from the request
$data = json_decode(file_get_contents("php://input"), true);
// Check if the required ID is provided
if (!empty($data['id'])) {
$cartItemId = $data['id'];
// Prepare the SQL query to delete the item from the cart
$sql = "DELETE FROM cart WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $cartItemId);
if ($stmt->execute()) {
echo json_encode([
"success" => true,
"message" => "Item successfully deleted from the cart."
]);
} else {
echo json_encode([
"success" => false,
"message" => "Failed to delete the item. Please try again."
]);
}
$stmt->close();
} else {
echo json_encode([
"success" => false,
"message" => "Invalid request. Item ID is missing."
]);
}
// Close the database connection
$conn->close();
?>