-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
162 lines (150 loc) · 4.77 KB
/
cart.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
<?php
if(isset($_POST['cakpic'])) {
$cakpic=$_POST['cakpic'];
}
if(isset($_POST['name'])) {
$name=$_POST['name'];
}
if(isset($_POST['ing'])) {
$ing=$_POST['ing'];
}
if(isset($_POST['sizcod'])) {
$sizcod=$_POST['sizcod'];
}
if(isset($_POST['price'])) {
$price=$_POST['price'];
}
if(isset($_POST['qty'])) {
$qty=$_POST['qty'];
}
$quantity=1;
$contact="";
if(!empty($_GET)) {
if(isset($_GET['cakpic'])) {
$cakpic=$_GET['cakpic'];
}
if(isset($_GET['name'])) {
$name=$_GET['name'];
}
if(isset($_GET['ing'])) {
$ing=$_GET['ing'];
}
if(isset($_GET['sizcod'])) {
$sizcod=$_GET['sizcod'];
}
if(isset($_GET['price'])) {
$price=$_GET['price'];
}
if(isset($_GET['qty'])) {
$qty=$_GET['qty'];
}
if(isset($_GET['quantity'])) {
$quantity=$_GET['quantity'];
}
if(isset($_GET['contact'])) {
$contact=$_GET['contact'];
}
if($quantity > $qty) {
echo '<script type="text/javascript">';
echo 'alert("Enter correct quantity");';
echo '</script>';
}
if($contact == "") {
echo '<script type="text/javascript">';
echo 'alert("Enter contact number");';
echo '</script>';
}
else if(!preg_match("/^[0-9]{10}+$/", $contact)) {
echo '<script type="text/javascript">';
echo 'alert("Enter correct contact number");';
echo '</script>';
}
else {
include "db.php";
$query = "SELECT MAX(ordcak) as max FROM tbord";
$result = mysqli_query($con, $query);
if($row = mysqli_fetch_array($result)) {
$ordcak = $row['max']+1;
}
else {
$ordcak = 1;
}
$query = "INSERT INTO tbord(ordcak, ordsizcod, ordphnno, ordqty) VALUES($ordcak, $sizcod, '$contact', $quantity)";
$query2 = "UPDATE tbsiz SET sizqty=".($qty-$quantity)." WHERE sizcod=$sizcod";
if(mysqli_query($con, $query)) {
mysqli_query($con, $query2);
header("location:payment.php?cakpic=$cakpic&name=$name&ing=$ing&price=$price&quantity=$quantity&contact=$contact");
}
else {
header("location:err.php");
}
}
}
if($qty <=0) {
header("location:index.php?err=lowQuant");
}
?>
<html>
<head>
<title></title>
<style>
.heading-primary {
font-size: 5rem;
font-weight: 200;
}
.util-center {
text-align:center;
position: absolute;
top: 25%;
left: 50%;
transform: translate(-50%, -50%);
}
.item-show {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
display: block;
margin: 5px;
height: 12rem;
width: 65vh;
padding: 5px;
border: 1px solid black;
}
.img {
height: 11rem;
width: 11rem;
float: left;
margin-right: 5rem;
}
.cake-detail {
text-align: left;
align-content: flex-start;
}
</style>
</head>
<body>
<div class="util-center">
<h1 class="heading-primary" id="head">Cart</h1>
</div>
<div class='item-show'>
<form method='get'>
<img class='img' src='<?php echo $cakpic; ?>'>
<div class='cake-detail'>
Name: <?php echo $name; ?><br>
Ingredient: <?php echo $ing ?><br>
Price: Rs.<?php echo $price ?><br>
</div>
<input type='hidden' value='<?php echo $cakpic; ?>' name='cakpic'>
<input type='hidden' value='<?php echo $name; ?>' name='name'>
<input type='hidden' value='<?php echo $ing; ?>' name='ing'>
<input type='hidden' value='<?php echo $sizcod; ?>' name='sizcod'>
<input type='hidden' value='<?php echo $price; ?>' name='price'>
<input type='hidden' value='<?php echo $qty; ?>' name='qty'>
<label for="quantity">Quantity : </label><input type="number" id="quantity" name="quantity" class="quantity" min="1" max="<?php echo $qty; ?>" value="<?php echo $quantity; ?>"><br>
<label for="contact">Contact : </label><input type="" id="contact" name="contact" class="contact" value="<?php echo $contact; ?>" maxlength="10"><br>
<button type="submit" value="Add to cart">Confirm Order</button>
</form>
</div>
</body>
</html>