-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder.php
More file actions
67 lines (56 loc) · 2.28 KB
/
order.php
File metadata and controls
67 lines (56 loc) · 2.28 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
$servername = "localhost";
$db_username = "your_db_username";
$db_password = "your_db_password";
$dbname = "mbzstore";
$conn = mysqli_connect('localhost', 'root', '', 'mbzstore');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
};
include 'common_functions.php';
if(isset($_GET['user_id'])){
$user_id=$_GET['user_id'];
}
// getting total items and total price of all items
$get_ip_address=getIPAddress();
$total_price=0;
$cart_query_price="Select * from `cart_details` where ip_address='$get_ip_address'";
$result_cart_price=mysqli_query($conn,$cart_query_price);
$invoice_number=mt_rand();
$status='pending';
$count_products=mysqli_num_rows($result_cart_price);
while($row_price=mysqli_fetch_array($result_cart_price)){
$product_id=$row_price['product_id'];
$select_product="Select * from `products` where product_id=$product_id";
$run_price=mysqli_query($conn,$select_product);
while($row_product_price=mysqli_fetch_array($run_price)){
$product_price=array($row_product_price['product_price']);
$product_values=array_sum($product_price);
$total_price+=$product_values;
}
}
// getting quantity from cart
$get_cart="select * from `cart_details`";
$run_cart=mysqli_query($conn,$get_cart);
$get_item_quantity=mysqli_fetch_array($run_cart);
$quantity=$get_item_quantity['quantity'];
if($quantity==0){
$quantity=1;
$subtotal=$total_price;
}else{
$quantity=$quantity;
$subtotal=$total_price*$quantity;
}
$insert_orders="Insert into `user_orders` (user_id,amount_due,invoice_number,total_products,order_date,order_status) values ($user_id,$subtotal,$invoice_number,$count_products,NOW(),'$status')";
$result_query=mysqli_query($conn,$insert_orders);
if($result_query){
echo "<script>alert('Order are submitted successfully')</script>";
echo "<script>window.open('profile.php','_self')</script>";
}
// orders pending
$insert_pending_orders="Insert into `orders_pending` (user_id,invoice_number,product_id,quantity,order_status) values ($user_id,$invoice_number,$product_id,$quantity,'$status')";
$result_pending_orders=mysqli_query($conn,$insert_pending_orders);
// delete items from cart
$empty_cart="Delete from `cart_details` where ip_address='$get_ip_address'";
$result_delete=mysqli_query($conn,$empty_cart);
?>