-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
86 lines (64 loc) · 2.9 KB
/
checkout.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
85
86
<?php
session_start();
if($_SESSION["customer-login"] != "true"){
header('Location: login.php');
}
$message = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
try {
require_once("connect-db.php");
$customer_id = $_POST["customer_id"];
$menu_ids = $_POST["menu_id"]; // Assuming menu_id is an array
// Insert order details into the customer_order table
$order_sql = "INSERT INTO customer_order (customer_id) VALUES (:customer_id)";
$order_statement = $db->prepare($order_sql);
$order_statement->bindValue(":customer_id", $customer_id);
$order_statement->execute();
// Get the last inserted customer_order_id
$customer_order_id = $db->lastInsertId();
// Insert menu items into the submit_order table
$submit_order_sql = "INSERT INTO submit_order (customer_order_id, menu_id) VALUES (:customer_order_id, :menu_id)";
$submit_order_statement = $db->prepare($submit_order_sql);
// Loop through each menu_id and insert into submit_order table
foreach ($menu_ids as $menu_id) {
$submit_order_statement->bindValue(":customer_order_id", $customer_order_id);
$submit_order_statement->bindValue(":menu_id", $menu_id);
$submit_order_statement->execute();
}
// Close statement connections
$order_statement->closeCursor();
$submit_order_statement->closeCursor();
$message = "<h4>The order is successful.</h4>";
} catch (Exception $e) {
$message = "<h4>Error submitting order: " . $e->getMessage() . "</h4>";
}
}
?>
<script>
window.location.replace("thankyou.php");
</script>
<!-- $message = "";
if($_SERVER["REQUEST_METHOD"]=="POST"){
require_once("connect-db.php");
$customer_order_id = $_POST["customer_order_id"];
$customer_id = $_POST["customer_id"];
$menu_ids = $_POST["menu_ids"];
$sql = "INSERT INTO customer_order (customer_order_id, customer_id) VALUES (:customer_order_id, :customer_id)";
$statement = $db->prepare($sql);
$statement->bindValue(":customer_order_id", $customer_order_id);
$statement->bindValue(":customer_id", $customer_id);
$sql2 = "INSERT INTO submit_order (customer_order_id, menu_id) VALUES (:customer_order_id, :menu_id)";
$statement = $db->prepare($sql2);
foreach ($menu_ids as $menu_id) {
$submit_order_statement->bindValue(":customer_order_id", $customer_order_id);
$submit_order_statement->bindValue(":menu_id", $menu_id);
$submit_order_statement->execute();
}
}
if($statement->execute()){
$statement->closeCursor();
$message = "<h4>The order is successful.</h4>";
}else{
$message = "<h4>Error submitting order.</h4>";
}
-->