-
Notifications
You must be signed in to change notification settings - Fork 1
/
deleteOrder.php
40 lines (33 loc) · 1.12 KB
/
deleteOrder.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
<?php
// session_start(); // Start the session
session_start();
// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
include 'config/db.php';
if (isset($_GET['id'])) {
$order_id = intval($_GET['id']); // Ensure order ID is an integer
// Now, perform the delete operation
$delete_sql = "DELETE FROM `orders` WHERE `order_no` = $order_id";
//insert delete time into order audit table
if ($conn->query($delete_sql) === TRUE) {
$updateDelTime = "UPDATE `orders_audit` SET `deleted_at` = NOW(), `deleted_by` = '".$_SESSION['email']."' WHERE `order_no` = $order_id";
}
if ($conn->query($updateDelTime) === TRUE) {
// Redirect to the referring page
if (isset($_SERVER['HTTP_REFERER'])) {
header("Location: " . $_SERVER['HTTP_REFERER']);
} else {
header("Location: order.php"); // A fallback page
}
exit();
}
} else {
echo "Error: No company found for this branch.";
}
// Close the database connection
$conn->close();
?>