-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteProduct.php
41 lines (33 loc) · 1.32 KB
/
deleteProduct.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
<?php
// deleteProduct.php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Access-Control-Allow-Methods: GET');
header('Content-Type: application/json');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
// Handle OPTIONS requests for preflight checks
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
http_response_code(200);
exit();
}
header('Content-Type: application/json');
include 'Conx.php'; // Ensure the correct path to your Conx.php file
// Check if the 'id' parameter exists in the query string and is a valid number
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$id = (int) $_GET['id'];
// Update the status to 1 (inactive) instead of deleting
$query = "UPDATE products SET status = 1 WHERE id = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('i', $id);
$stmt->execute();
if ($stmt->affected_rows > 0) {
echo json_encode(['success' => true, 'message' => 'Product status updated to inactive.']);
} else {
echo json_encode(['success' => false, 'message' => 'Product not found or update failed.']);
}
$stmt->close();
} else {
echo json_encode(['success' => false, 'message' => 'Invalid product ID']);
}
$conn->close();
?>