-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha-order.php
More file actions
67 lines (45 loc) · 1.76 KB
/
Copy patha-order.php
File metadata and controls
67 lines (45 loc) · 1.76 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
67
<?php
include('connection.php');
if(isset($_POST['checkout'])){
//orders table
$item_id =$_POST['item_id']; //item id
$client_id =$_POST['client_id']; //client id
$order_amount =$_POST['order_amount'];//order price per item
$order_quan =$_POST['order_quan']; //quantity
$date_ordered = $_POST['date_ordered'];
$order_time = $_POST['order_time'];
//CART table
$idcart = $_POST['idcart'];
//stocks table
$quantity = $_POST['quantity'];
// $stock = "0";
// $status = "out-of-stock";
$status = "out-of-stock";
$quan = "0";
$remarks ="waiting";
//order price = order quantity * price
$order_amount=$order_quan*$order_amount;
//if checkout button is pressed insert data to `orders` table
$check = mysqli_query($conn, "insert into `orders` (item_id,client_id,oo_quan,order_quan,order_amount,date_ordered,order_time,remarks) values ('$item_id','$client_id','$order_quan','$order_quan','$order_amount','$date_ordered','$order_time','$remarks')");
if($check)
{
//if data is already inserted delete data from cart using idcart
mysqli_query($conn, "delete from `cart` where idcart = '$idcart'");
header("location: cli-order.php");
}
if($check)
{
$up_quantity = $quantity - $order_quan;
mysqli_query($conn, "UPDATE `stocks` SET `quantity` = '$up_quantity' WHERE `s_id` = '$item_id'");
}
if($check)
{
$check_s = mysqli_query($conn, "SELECT *FROM `stocks` WHERE quantity ='$quan'");
$checkered = mysqli_num_rows($check_s);
if($checkered > 0)
{
mysqli_query($conn, "UPDATE `stocks` SET `status` = '$status' WHERE `s_id` = '$item_id'") or die(mysqli_error());
}
}
}
?>