-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete_order.php
More file actions
48 lines (39 loc) · 1.07 KB
/
complete_order.php
File metadata and controls
48 lines (39 loc) · 1.07 KB
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
44
45
46
47
48
<?php
session_start();
include 'db.php';
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
header("Location: login.php");
exit();
}
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
echo "Invalid order ID.";
exit();
}
$order_id = $_GET['id'];
// Check if order exists
$check_sql = "SELECT id, status FROM orders WHERE id = ?";
$stmt = $conn->prepare($check_sql);
$stmt->bind_param("i", $order_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows === 0) {
echo "Order not found.";
exit();
}
$order = $result->fetch_assoc();
// Prevent re-completing an already completed order
if ($order['status'] === 'Completed') {
echo "This order is already completed.";
exit();
}
// Update order status
$update_sql = "UPDATE orders SET status = 'Completed' WHERE id = ?";
$stmt = $conn->prepare($update_sql);
$stmt->bind_param("i", $order_id);
if ($stmt->execute()) {
header("Location: view_orders.php?message=Order Completed Successfully!");
exit();
} else {
echo "Error updating order: " . $conn->error;
}
?>