-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.php
More file actions
56 lines (39 loc) · 1.47 KB
/
Copy pathorder.php
File metadata and controls
56 lines (39 loc) · 1.47 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
<?php
/**
* Created by IntelliJ IDEA.
* User: mithishri
* Date: 10/1/2016
* Time: 7:48 PM
*/
session_start();
if (isset($_SESSION['id'])) {
include('conn.php');
$order = json_decode($_POST['order'], true);
$items = $order['items'];
$uid = $_SESSION['id'];
$resid = $_SESSION['res_id'];
$now = date("Y-m-d H:i:s");
$query = "INSERT INTO orders (res_id, u_id, address, bill, phone, o_time, request, u_name)
VALUES ('$resid', '$uid', '" . $order['address'] . "',
'" . $order['bill'] . "', '" . $order['phone'] . "', '" . $now
. "', '" . mysqli_real_escape_string($link, $order['request']) . "','" . $order['name'] . "')";
if (mysqli_query($link, $query)) {
$id = mysqli_insert_id($link);
$query = "INSERT INTO order_items(o_id, item, quantity, rate)
VALUES ";
foreach ($order['items'] as $i => $item) {
//print_r($item);
if ($i == 0)
$query .= "('$id', '" . $item['item']['name'] . "', " . $item['quantity'] . "," . $item['item']['rate'] . ")";
else
$query .= " , ('$id', '" . $item['item']['name'] . "', " . $item['quantity'] . "," . $item['item']['rate'] . ")";
}
if (mysqli_query($link, $query)) {
echo 'Successfully placed order.';
} else
echo 'Unsuccessfull in placing order.';
} else {
echo 'Unsuccessfull in placing order.';
}
}
?>