-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplace_order.php
More file actions
66 lines (54 loc) · 2.23 KB
/
Copy pathplace_order.php
File metadata and controls
66 lines (54 loc) · 2.23 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
require_once "conn.php";
require_once "nav.php";
// session_start();
if (!isset($_SESSION["customer_id"])) {
echo "<script>alert('Login to place order');";
echo "window.location.href = 'login.php';</script>";
exit();
} else {
$UID = $_SESSION['customer_id'];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["payment"])) {
$selected_payment_mode = $_POST["payment"];
} else {
echo "<script> alert('Error ocurred.please check payment details');";
echo "window.history.back();</script>";
}
$pid = $_POST['pid'];
$price = $_POST['price'];
echo $price;
//$quantity = $_POST['qty'];
$stmt1 = $conn->prepare("SELECT SID FROM product WHERE PID = $pid");
$stmt1->execute();
$get_SID = $stmt1->get_result();
if ($get_SID->num_rows > 0) {
while ($SIDrow = $get_SID->fetch_assoc()) {
$SID = $SIDrow['SID'];
}
}
if (isset($_POST['address_selection'])) {
$selectedAddressId = $_POST['address_selection'];
$_SESSION['cid'] = $selectedAddressId;
} else {
echo "<script> alert('Please add an address to continue to place order');";
echo "window.history.back();</script>";
}
date_default_timezone_set("Asia/Kolkata");
$orderDate = time();
$order_status = '';
$payment_status = '';
if ($selected_payment_mode === 'cod') {
$payment_status = 'not_paid';
$order_status = 'confirmed';
}
$delivery_status = 'pending';
$stmt = $conn->prepare("INSERT INTO orders(CID,UID,SID,PID,order_time,order_status,price,payment_mode,payment_status,delivery_status) VALUES(?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("iiiiisisss", $selectedAddressId, $UID, $SID, $pid, $orderDate, $order_status, $price, $selected_payment_mode, $payment_status, $delivery_status);
$stmt->execute();
// header("location:orders.php");
echo "<script>alert('Order confirmed');";
echo "window.location.href = 'customer_orders_page.php';</script>";
}
}
?>