-
Notifications
You must be signed in to change notification settings - Fork 5
/
order.php
171 lines (134 loc) · 4.26 KB
/
order.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
<html>
<head>
<title>The Bliss - We Got Your Event</title>
<link rel="icon" href="Images/WEB logo.png" type="image/gif"> <!--icon next to the title-->
<link rel="stylesheet" type="text/css" href="The Bliss.css">
<script language="javascript" type="text/javascript" src="The Bliss.js"></script>
</head>
<body bgcolor="#eed4ff">
<?php
$servername = "localhost";
$user = "root";
$pw = "";
$db = "TheBliss";
$connection = mysqli_connect($servername, $user, $pw, $db); /*connecting the database*/
if(!$connection)
{
die("Connection failed: " .mysqli_connect_error());
}
$fname = $_POST["fname"];
$lname = $_POST["lname"];
$add = $_POST["address"];
$mail = $_POST["mail"];
$phone = $_POST["phone"];
$desc = $_POST["description"];
if($fname=="" || $lname=="" || $add=="" || $mail=="" || $phone=="") /*validating the shipping details*/
{
?>
<center>
<div>
<img src='Images/WEB logo.png' width='250px' height='250px'>
</div>
<div style='background-color:black;
font-family:trebuchet ms;
font-size:40px;
color:#f1f1f1;
padding:5px;
margin-top:20px;
border-radius:30px;
width:65%;'>
You have not entered all required fields<br>Please enter all fields and place the order
</div>
</center>
<center>
<div>
<input type="button" name="redirect" value="Back" id="submitButton" class="bothButtons" onclick="window.location.href ='http://localhost/TheBliss/checkout.php';" style="font-size:35px; margin-top:50px; border-radius:5px;">
</div>
</center>
<?php
}
else if(strlen($phone)!=10 || !is_numeric($phone)) /*validating the phone number*/
{
?>
<center>
<div>
<img src='Images/WEB logo.png' width='250px' height='250px'>
</div>
<div style='background-color:black;
font-family:trebuchet ms;
font-size:40px;
color:#f1f1f1;
padding:5px;
margin-top:20px;
border-radius:30px;
width:65%;'>
Incorrect phone number format<br>Please re-enter and place the order again
</div>
</center>
<center>
<div>
<input type="button" name="redirect" value="Back" id="submitButton" class="bothButtons" onclick="window.location.href ='http://localhost/TheBliss/checkout.php';" style="font-size:35px; margin-top:50px; border-radius:5px;">
</div>
</center>
<?php
}
else /*entering details to the database*/
{
$selectqry = "SELECT * from cart";
$result=mysqli_query($connection,$selectqry);
if(mysqli_num_rows($result)>0) /*checking if the cart has 1 or more rows*/
{
$selectallorder = "SELECT * FROM orderproducts";
$orderresult = mysqli_query($connection,$selectallorder);
if(mysqli_num_rows($orderresult)==0) /*checking if order table is empty, if tru, oid=1*/
{
$oid=1;
}
else
{
$selectmaxOID = "SELECT MAX(orderid) AS maxoid FROM orderproducts"; /*if order table not empty, selecting MAX value from orderid column*/
$maxoidresult = mysqli_query($connection,$selectmaxOID);
$oidrow = mysqli_fetch_array($maxoidresult); /*fetching the row with MAX orderid*/
$oid=$oidrow['maxoid']; /*assigning max order id to a variable*/
$oid++;
}
while($row=mysqli_fetch_assoc($result)) /*iterating the rows in the cart*/
{
$pid = $row["productid"];
$qty = $row["qty"];
$insertquery = "INSERT INTO orderproducts (orderid,fname,lname,address,email,phone,description, productid, qty) VALUES ('$oid','$fname', '$lname', '$add', '$mail', '$phone', '$desc', '$pid', '$qty')";
$insertresult = mysqli_query($connection, $insertquery);
}
}
if($insertresult)
{
echo "<center>
<div>
<img src='Images/WEB logo.png' width='250px' height='250px'>
</div>
<div style='background-color:black;
font-family:trebuchet ms;
font-size:40px;
color:#f1f1f1;
padding:5px;
margin-top:20px;
border-radius:30px;
width:65%;'>
Order placed successfully!<br>
Your order will be delivered within 3-4 days :)
</div>
</center>";
$emptycart = "DELETE FROM cart"; /*emptying the cart after placing the order*/
$deleteresult = mysqli_query($connection,$emptycart);
}
?>
<center>
<div>
<input type="button" name="redirect" value="Continue Shopping" id="submitButton" class="bothButtons" onclick="Home()" style="font-size:35px; margin-top:50px; border-radius:5px;">
</div>
</center>
<?php
}
?>
</body>
</html>