-
Notifications
You must be signed in to change notification settings - Fork 21
/
ThankYouCheckout.php
128 lines (87 loc) · 4.3 KB
/
ThankYouCheckout.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
define('Access', TRUE);
//START SESSION
include "./AdditionalPHP/startSession.php";
//CONNECTION TO DATABASE : cakeshop
include_once 'connection.php';
//USER COMPLETED PAYMENT
//CREATE ORDER ID FOR USER
//FIRST -- FIND PHONE NUMBER
$Q_select_user_phone = 'SELECT phone FROM user WHERE userID = '.$_SESSION['userID'];
$run_select_user_phone = mysqli_query($conn, $Q_select_user_phone);
//IF USER HAS NO PHONE NUM --> SET SESSION TO NULL
if(mysqli_num_rows($run_select_user_phone)==0){
$_SESSION['phone'] = null;
}
//ELSE SET SESSION TO CURRENT PHONE NUM
else{
$result_phone = mysqli_fetch_array($run_select_user_phone);
$_SESSION['phone'] = $result_phone[0];
}
//ADD DATA TO USERORDER
$Q_insert_userorder ='INSERT INTO userorder (userID, total, address, phone, status)
VALUES ('.$_SESSION['userID'].','.$_SESSION['total_price'].',"'.$_POST['address_checkout'].'","'.$_SESSION['phone'].'", "successful")';
$run_insert_userorder = mysqli_query($conn, $Q_insert_userorder);
//INSERT INTO ORDERITEM
//SELECT DATA NEEDED FIRST
$Q_select_all_cartitem = 'SELECT * FROM cartitem WHERE cartID ='.$_SESSION['cartID'];
$run_select_all_cartitem = mysqli_query($conn, $Q_select_all_cartitem);
$Q_select_orderID = 'SELECT orderID FROM userorder WHERE userID ='. $_SESSION['userID'];
$run_select_orderID = mysqli_query($conn, $Q_select_orderID);
$result3 = mysqli_fetch_array($run_select_orderID, MYSQLI_NUM);
$_SESSION['orderID'] = $result3[0];
//LOOP THROUGH EVERY CART ITEM
while($row = mysqli_fetch_assoc($run_select_all_cartitem)){
//INSERT EACH CART ITEM AS ORDER ITEM IN ORDERITEM TABLE
$Q_insert_orderitem = 'INSERT INTO orderitem (productID, orderID, price, quantity)
VALUES ('.$row['productID'].', '.$_SESSION['orderID'].','.$row['price'].','.$row['quantity'].')';
$run_insert_orderitem = mysqli_query($conn, $Q_insert_orderitem);
}
//INSERT INTO TRANSACTION
$Q_insert_into_transaction = 'INSERT INTO transaction (userID, orderID, paymentMethod, status)
VALUES ( '.$_SESSION['userID'].', '.$_SESSION['orderID'].',"'.$_POST['paymentMethod'] .'","successful" )';
$run_insert_into_transaction = mysqli_query($conn, $Q_insert_into_transaction);
//AFTER INSERTING DATA TO TABLES, WE HAVE TO UNSET SHOPPING CART SESSION
foreach($_SESSION['shopping_cart'] as $key => $product){
unset($_SESSION['shopping_cart'][$key]);
// unset($product_ids[$key]);
}//end foreach
//DELETE CARTITEM VALUES AFTER CHECKOUT
$Q_delete_cartitem = 'DELETE FROM cartitem WHERE cartID ='.$_SESSION['cartID'];
$run_delete_cartitem = mysqli_query($conn, $Q_delete_cartitem);
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MALAKO | Thank you!</title>
<!-- BOOTSTRAP CORE CSS -->
<link href="checkout/bootstrap.min.css" rel="stylesheet">
<!-- CSS -->
<link href="checkout/form-validation.css" rel="stylesheet">
<!-- ANIMATE.CSS -->
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css"/>
</head>
<body >
<!-- TITLE -->
<div class="py-5 text-center">
<h1 class="business-name">MALAKO</h1>
<img class="thankYouImageHead my-5" src="Assets/images/cart/circleHead.png" />
<img class="thankYouImage my-5 rotate" src="Assets/images/cart/sun.png" />
<h1 style="font-size:3vw;">Thank You for shopping with us!</h1>
<a href="index.php" class=" btn btn-primary btn-lg button" style="font-size:1.5vw;">Home</a>
</div>
<!-- FOOTER -->
<footer class="my-5 pt-5 text-muted text-center text-small">
<p class="mb-1">© 2020 MALAKO</p>
<ul class="list-inline">
<li class="list-inline-item"><a href="#">Privacy</a></li>
<li class="list-inline-item"><a href="#">Terms</a></li>
<li class="list-inline-item"><a href="#">Support</a></li>
</ul>
</footer>
</body>
</html>