-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathshopping-cart.php
224 lines (147 loc) · 7.09 KB
/
shopping-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
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
<?php
include_once 'includes/db_connect.php';
session_start();
$keys = $_SESSION['cart'];
$array = array_fill_keys($keys, 1);
if (isset($_SESSION['cart'])) {
# code...
$whereIn = implode(',', $_SESSION['cart']);
$sql = "SELECT * FROM product WHERE id IN ($whereIn)";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
$lense=0;
}
}
?>
<?php
if ( isset( $_POST['empty-cart'] ) ) {
unset($_SESSION['cart']);
header('Location: ./shopping-cart.php');
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Virtual Eye Shop !</title>
<link rel="stylesheet" type="text/css" href="frontEnd.css">
</head>
<body>
<header>
<img src="img/marvel.png" alt="logo">
</header>
<?php
include('main-menu.php');
?>
<nav id="search-nav">
<center>
<form method="POST" action="search-result.php">
<input type="text" name="keyword" placeholder="Type an item">
<select name="catagory">
<option value ="22">camera</option><option value ="23">Lense</option><option value ="24">Memory Card</option><option value ="25">Camera Bag</option><option value ="26">Accesories</option><option value ="27">DSLR</option><option value ="28">Digital Camera</option><option value ="29">Cam Recorder</option><option value ="30">Flash</option><option value ="31">Tripod</option>
</select>
<button type="submit" name="search">Search</button>
</form>
</center>
</nav>
<section id="form"><!--form-->
<div class="container">
<div class="row">
<div style="margin-top:20px">
<table border="1" style="width:90%" >
<thead class="bg-primary">
<th>Item</th>
<th>Price</th>
<th >Qty</th>
<th>Total</th>
</thead>
<tbody>
<?php $total = 0; ?>
<?php if($result->num_rows > 0){ ?>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td class="text-center"><strong><?php echo $row['name'];?></strong></td>
<td class="text-center"><?php echo $row['price']-$row['promotion'];?></td>
<td class="text-center">
<form action="" method="POST">
<input type="hidden" name="id" value="<?php echo $id;?>" />
<input type="number" name="quantity" value="<?php echo $array[$row['id']]?>" min="1" style="width:50px;"/>
<button type="submit" name ="update-cart"class="btn btn-info">Update</button>
</form>
</td>
<?php $itotal = $row['price']-$row['promotion']; ?>
<td class="text-center"><font class="itotal"><?php echo $itotal; ?></font></td>
<?php if($row['catagory_id']==27){
$lense++;
} ?>
<?php
// $array = array_merge($array, array($row['id'] =>2 ));
?>
</tr>
<?php $total = $total + $itotal;?>
<?php } ?>
</tbody>
</table>
<br>
<?php echo "Total amount : <strong>".$total."</strong> RM"; ?><br>
<?php echo "GST 6 %: <strong>".$tax=(($total*6)/100)." <strong> RM"; ?><br>
Total : <?php echo $tax+$total; ?></p>
<div class="pull-right">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<button name="empty-cart">Empty Cart!!!</button>
<a href ="checkout.php">Check Out!!!</a>
</form>
</div>
<?php }
else{ ?>
<tr><td colspan="5" class="text-center alert alert-danger"><strong>*** Your Cart is Empty ***</strong></td></tr>
</tbody>
</table>
<?php } ?>
</div>
</div>
</div>
</section><!--/form-->
<?php if ($lense>0) {
?>
<?php
$sql = "SELECT *
FROM product
WHERE catagory_id = 23 LIMIT 2
";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
?>
<center>
<h3>You might be interested to configure with following components</h3></center>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<center>
<div class="img"><a href="#"><img alt="" height="200" width="200" src="<?php echo $row['image']; ?>" ></a></div>
<div class="info">
<a class="title" href="product-details.php"><?php echo $row['name']; ?></a>
<div class="price">
<span class="st">Our price:</span><strong>$<?php echo $row['price']; ?></strong>
</div>
<div class="actions">
<a href="add-to-cart.php?id=<?php echo $row['id'] ?>"><button >Add to Cart</button></a>
</div>
</div>
</center>
<?php
}
}
else {
echo "No result found";
}
?>
<?php
$lense--;
}
?>
<footer>
Copyright @University of Malaya
</footer>
</body>
</html>