-
Notifications
You must be signed in to change notification settings - Fork 6
/
checkout.php
246 lines (226 loc) · 11 KB
/
checkout.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<?php
session_start();
include 'connection.php';
include 'header.php';
$cust_id = 0;
$proid = 0;
$proname = "";
$proprice = 0;
?>
<html>
<body>
<!-- SIdeNav Mobile -->
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<input type="text" id="mySearch" onkeyup="myFunction()" placeholder="Search.." title="Type in a category">
<a href="02.html">Women</a>
<a href="02.html">Jeans</a>
<a href="02.html">Jackets</a>
<a href="02.html">Best Sales</a>
</div>
<!-- Script for SideNav Mobile -->
<script>
function openNav() {
if (document.getElementById("mySidenav").style.width == "250px") {
document.getElementById("mySidenav").style.width = "0";
} else {
document.getElementById("mySidenav").style.width = "250px";
}
}
function closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
</script>
<h2 style="text-align: center;">CHECKOUT</h2>
<div style="margin: 2%;" class="chrow">
<div class="col-75">
<div class="chcontainer">
<form action="" method="POST">
<div class="chrow">
<div class="col-50">
<h3>Shipping Address</h3>
<label for="fname"><i class="fa fa-user"></i> Full Name</label>
<input type="text" id="fname" name="firstname" placeholder="Wali Muhammad" required>
<label for="email"><i class="fa fa-envelope"></i> Email</label>
<input type="text" id="email" name="email" placeholder="wali@example.com" required>
<label for="adr"><i class="fa fa-address-card-o"></i> Address</label>
<input type="text" id="adr" name="address" placeholder="G11 Markaz, ISB" required>
<label for="city"><i class="fa fa-institution"></i> City</label>
<input type="text" id="city" name="city" placeholder="Islamabad" required>
<div class="chrow">
<div class="col-50">
<label for="state">State</label>
<input type="text" id="state" name="state" placeholder="Islamabad" required>
</div>
<div class="col-50">
<label for="zip">Zip</label>
<input type="text" id="zip" name="zip" placeholder="44000" required>
</div>
</div>
</div>
<div class="col-50">
<h3>Payment</h3>
<label for="fname">Accepted Cards</label>
<div class="icon-container">
<i class="fa fa-cc-visa" style="color:navy;"></i>
<i class="fa fa-cc-amex" style="color:blue;"></i>
<i class="fa fa-cc-mastercard" style="color:red;"></i>
<i class="fa fa-cc-discover" style="color:orange;"></i>
</div>
<label for="cname">Name on Card</label>
<input type="text" id="cname" name="cardname" placeholder="Wali Muhammad">
<label for="ccnum">Credit card number</label>
<input type="text" id="ccnum" name="cardnumber" placeholder="1111-2222-3333-4444">
<label for="expmonth">Exp Month</label>
<input type="text" id="expmonth" name="expmonth" placeholder="September">
<div class="chrow">
<div class="col-50">
<label for="expyear">Exp Year</label>
<input type="text" id="expyear" name="expyear" placeholder="2024">
</div>
<div class="col-50">
<label for="cvv">CVV</label>
<input type="text" id="cvv" name="cvv" placeholder="352">
</div>
</div>
</div>
</div>
<input type="submit" name="place_order" value="Place Order" class="chbtn">
</form>
</div>
</div>
<?php
$cust_id = 0;
$existed = false;
$placed = false;
if(!empty($_SESSION["loggedin"])){
$cust_id = $_SESSION["id"];
}
if(isset($_POST["place_order"]))
{
$ful_name = $_POST["firstname"];
$e_mail = $_POST["email"];
$add = $_POST["address"];
$cit = $_POST["city"];
$sta = $_POST["state"];
$zi = $_POST["zip"];
$sqladd = "SELECT cus_id FROM address WHERE cus_id = $cust_id";
$result = $conn->query($sqladd);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if($cust_id == $row["cus_id"])
{
$existed = true;
}
}
}
if($existed)
{
$sql = "UPDATE address SET cus_id = $cust_id, f_name = '$ful_name', e_mail = '$e_mail', s_address = '$add', city = '$cit', state = '$sta', zip = '$zi' WHERE cus_id = $cust_id";
if ($conn->query($sql) === TRUE) {
$placed = true;
} else {
$placed = false;
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
else{
$sql = "INSERT INTO address VALUES ($cust_id, '$ful_name', '$e_mail', '$add', '$cit', '$sta', '$zi')";
if ($conn->query($sql) === TRUE) {
$placed = true;
} else {
$placed = false;
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$dt=date("Y-m-d");
$sql1 = "INSERT INTO orders VALUES (default, $cust_id, '$dt')";
if ($conn->query($sql1) === TRUE) {
$placed = true;
} else {
$placed = false;
echo "Error: " . $sql . "<br>" . $conn->error;
}
$max_oid = 0;
$oql = "SELECT MAX(o_id) as maxid FROM orders";
$result = $conn->query($oql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
if($row["maxid"] > 0)
{
$max_oid = $row["maxid"];
}
}
}
$sql2 = "UPDATE cart SET ordered = 1, order_id = $max_oid WHERE cus_id = $cust_id && ordered = 0";
if ($conn->query($sql2) === TRUE) {
$placed = true;
} else {
$placed = false;
echo "Error: " . $sql . "<br>" . $conn->error;
}
if($placed == true)
{
function open_window(){
echo '<script>window.location="order.php";</script>';
}
// test:
open_window();
echo '<div id="NotiWindow" class="Notimodal">
<div class="Notimodal-content">
<span class="Noticlose">×</span>
<p>Order Placed Successfuly!</p>
</div>
</div>';
}
}
?>
<div class="col-25">
<div class="chcontainer">
<h4>Cart <span class="checkprice" style="color:black"><i class="fa fa-shopping-cart"></i> <b></b></span></h4>
<?php
$t_price = 0;
$p_price = 0;
if(!empty($_SESSION["loggedin"])){
$cust_id = $_SESSION["id"];
}
if($cust_id != 0)
{
$sql = "SELECT p.pro_id, p.pro_name, p.price, c.pro_quantity FROM products p
LEFT JOIN cart c ON p.pro_id = c.pro_id
LEFT JOIN customers s ON s.cus_id = c.cus_id
WHERE s.cus_id = $cust_id && c.ordered = 0";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$p_price = $row["price"] * $row["pro_quantity"];
$t_price += $p_price;
echo '<p><a href="product.php?'. $row["pro_id"] .'">'. $row["pro_name"] .'</a> <span class="checkprice">PKR '. $p_price .'</span></p>';
}
}
}
?>
<hr>
<p>Total <span class="price" style="color:black"><b>PKR <?php echo $t_price; ?></b></span></p>
</div>
</div>
</div>
<?php require_once "footer.php"; ?>
<!-- Script for NotiWindow-->
<script>
var modal = document.getElementById("NotiWindow");
var span = document.getElementsByClassName("Noticlose")[0];
function displayNoti() {
modal.style.display = "block";
}
span.onclick = function() {
modal.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>