-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_coupon.php
37 lines (26 loc) · 942 Bytes
/
delete_coupon.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
<?php
include("./layouts/session.php");
include 'conn.php'; // Include database connection
// Establish the connection to the user's database
$conn = connectMainDB();
header('Content-Type: application/json');
// Get the JSON input
$data = json_decode(file_get_contents("php://input"), true);
// Check if ID is provided
if (isset($data['id'])) {
$couponId = $data['id'];
// Prepare the DELETE statement
$stmt = $conn->prepare("DELETE FROM coupons WHERE id = ?");
$stmt->bind_param("i", $couponId);
// Execute the query
if ($stmt->execute()) {
echo json_encode(['success' => true, 'message' => 'Coupon deleted successfully.']);
} else {
echo json_encode(['success' => false, 'message' => 'Failed to delete the coupon.']);
}
// Close connections
$stmt->close();
$conn->close();
} else {
echo json_encode(['success' => false, 'message' => 'Coupon ID not provided.']);
}