-
Notifications
You must be signed in to change notification settings - Fork 0
/
order.php
153 lines (133 loc) · 5.78 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
<?php
include('front-end/partials/menu.php');
?>
<section id="order" class="container-fluid">
<div class="heading text-center">
<h1>Order now</h1>
</div>
<div class="row justify-content-center">
<form action="" class="col-md-7" method="POST">
<?php
if(isset($_GET['id'])){
$id=$_GET['id'];
//create sql query
$sql = "SELECT * FROM tbl_dishes WHERE id=$id";
//execute the query
$res=mysqli_query($conn,$sql);
//count no of rows to check whether there is data in database or not
$count = mysqli_num_rows($res);
if($count==1){
$rows = mysqli_fetch_assoc($res);
$title = $rows['title'];
$price = $rows['price'];
$image_name = $rows['image_name'];
}else{
//food not available
echo '<script>alert("Dish not found")</script>';
header('location:'.SITEURL);
}
}else{
//redirect to home
header('location:'.SITEURL);
echo '<script>alert("Please select the dish first!!")</script>';
}
?>
<div class="selected">
<table>
<tr>
<th>
<?php
if($image_name!=''){
?>
<img src="<?php echo SITEURL;?>images/food/<?php echo $image_name?>" alt="" width=250px>
<?php
}else{
?>
<img src="<?php echo SITEURL;?>img.png" alt="" width=250px>
<?php
}
?>
</th>
<th>
<div class="selection">
<div class="inputBox">
<input type="text" name="selected-food" value="<?php echo $title?>" readonly>
</div>
<div class="inputBox">
<input type="text" name="price" value="<?php echo $price?> Rs./-" readonly>
</div>
<div class="inputBox">
<input type="number" name = "qty" placeholder="Quantity" required>
</div>
</div>
</th>
</tr>
</table>
</div>
<div class="select">
<div class="inputBox">
<input type="text" name="selected-food" value="<?php echo $title?>" readonly>
</div>
<div class="inputBox">
<input type="text" name="price" value="Rs.<?php echo $price?>" readonly>
</div>
<div class="inputBox">
<input type="number" name = "qty" placeholder="Quantity" value="1" required>
</div>
</div>
<div class="inputBox">
<input type="text" name="customer_name" placeholder="Full Name" required>
</div>
<div class="inputBox">
<input type="text" name="customer_contact" placeholder="Phone no" required>
</div>
<div class="inputBox">
<input type="text" name="customer_email" placeholder="E-mail id" required>
</div>
<div class="inputBox">
<textarea name="customer_address" id="" cols="30" rows="10" placeholder="Address" required></textarea>
</div>
<input type="submit" name="submit" value="Place Order">
</form>
<?php
if(isset($_POST['submit'])){
//get all the details from the form
$qty = $_POST['qty'];
$total = $price * $qty;
$customer_name = $_POST['customer_name'];
$customer_contact = $_POST['customer_contact'];
$customer_email = $_POST['customer_email'];
$customer_address = $_POST['customer_address'];
$order_date = date("Y-m-d h:i:s a");
$status = "Ordered";
//create sql query
$sql2 = "INSERT INTO tbl_order SET
food = '$title',
price = '$price',
qty = '$qty',
total = '$total',
status = '$status',
customer_name = '$customer_name',
customer_contact = '$customer_contact',
customer_email = '$customer_email',
customer_address = '$customer_address',
order_date = '$order_date'
";
//execute the query
$res2 = mysqli_query($conn,$sql2);
if($res2==TRUE){
//order placed
echo '<script>alert("Order Placed Successfully!!")</script>';
echo("<script>location.href = '".SITEURL."';</script>");
}else{
//failed to place order
echo '<script>alert("Failed to place order!! Try again later")</script>';
echo("<script>location.href = '".SITEURL."';</script>");
}
}
?>
</div>
</section>
<?php
include('front-end/partials/footer.php');
?>