-
Notifications
You must be signed in to change notification settings - Fork 0
/
orders-update.php
41 lines (34 loc) · 1.37 KB
/
orders-update.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
<?php
if (session_id() == "" || !isset($_SESSION)) {
session_start();
}
include "config.php";
if (isset($_SESSION["cart"])) {
$total = 0;
foreach ($_SESSION["cart"] as $F_ID => $quantity) {
$result = $mysqli->query("SELECT * FROM FOOD WHERE id = " . $F_ID);
if ($result) {
if ($obj = $result->fetch_object()) {
$cost = $obj->price * $quantity;
$user = $_SESSION["username"];
$query = $mysqli->query(
"INSERT INTO orders (product_code, product_name, product_desc, price, units, total, email) VALUES('$obj->product_code', '$obj->product_name', '$obj->product_desc', $obj->price, $quantity, $cost, '$user')"
);
if ($query) {
$newqty = $obj->qty - $quantity;
if (
$mysqli->query(
"UPDATE products SET qty = " .
$newqty .
" WHERE id = " .
$F_ID
)
) {
}
}
}
}
}
}
header("location:bill.php");
?>