-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm.php
84 lines (71 loc) · 3.41 KB
/
confirm.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Check if 'order_id' is set in the POST data
if (isset($_POST["order_id"])) {
$order_id = $_POST["order_id"];
$servername = "localhost";
$username = "Atharav";
$password = "Atharav@31";
$dbname = "project";
// Create a new database connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare the SQL statement to retrieve the order status
$sql = "SELECT status FROM details WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $order_id);
$stmt->execute();
$result = $stmt->get_result();
if ($stmt === false) {
die("Prepare failed: " . $conn->error);
}
// Check if the order with the provided ID exists
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$status = $row["status"];
var_dump($status);
if ($status === 'pending') {
// Prepare the SQL statement to update the order status to 'confirmed'
$updateStatusSql = "UPDATE details SET status='confirmed' WHERE id = ?";
$updateStmt = $conn->prepare($updateStatusSql);
if ($updateStmt === false) {
die("Prepare failed: " . $conn->error);
}
// Bind the order ID parameter for the update statement
$updateStmt->bind_param("i", $order_id);
// Execute the update query
$updateStmt->execute();
if ($updateStmt->error) {
// Display an error alert
echo '<script>alert("Error updating status: ' . $updateStmt->error . '");</script>';
} else {
// Order has been confirmed, display a success alert and redirect
echo '<script>alert("Order has been confirmed.");</script>';
echo '<script>window.location.href = "customerbookinghtml.php";</script>'; // Redirect to customerbookinghtml.php
// Close the update statement
$updateStmt->close();
}
} elseif ($status === 'confirmed') {
// Display an alert for an already confirmed order
echo '<script>alert("This order is already confirmed. Order ID: ' . $order_id . '");</script>';
echo '<script>window.location.href = "customerbookinghtml.php";</script>'; // Redirect to customerbookinghtml.php
} else {
// Display an alert for an order that cannot be confirmed
echo '<script>alert("This order cannot be confirmed. Status: ' . $status . '");</script>';
echo '<script>window.location.href = "customerbookinghtml.php";</script>'; // Redirect to customerbookinghtml.php
}
} else {
// Display an alert for an order not found
echo '<script>alert("Order not found. Order ID: ' . $order_id . '");</script>';
}
// Close the prepared statement and the database connection
$stmt->close();
$conn->close();
} else {
// Display an alert for a missing order ID
echo '<script>alert("Order ID not provided.");</script>';
}
}
?>