-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplace-order.php
42 lines (30 loc) · 1.05 KB
/
place-order.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
<?php
session_start();
include 'configs/database.php';
function getMysqlDatetimeFromDate(int $day, int $month, int $year)
{
$dt = new DateTime();
$dt->setDate($year, $month, $day);
$dt->setTime(0, 0, 0, 0);
return $dt->format('Y-m-d H:i:s');
}
if (isset($_POST)) {
$data = file_get_contents('php://input');
$json = json_decode($data, true);
$json = $json['data'];
try {
$query = "INSERT INTO orders (title, price, quantity, order_date, user) VALUES (?, ?, ?, ?, ?)";
$prepared_statement = $conn->prepare($query);
foreach ($json as $item) {
$price = intval(str_replace('Rs. ', '', $item['price']));
$dt = getMysqlDatetimeFromDate(date('d'), date('m'), date('Y'));
$id = $_SESSION['user_id'];
$prepared_statement->bind_param('siisi', $item['title'], $price, $item['quantity'], $dt, $id);
$prepared_statement->execute();
}
$prepared_statement->close();
echo 'Success';
} catch (Exception $e) {
echo 'Error';
}
}