-
Notifications
You must be signed in to change notification settings - Fork 15
/
cart.php
executable file
·301 lines (175 loc) · 10.9 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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<!Doctype>
<?php
session_start();
include("functions/functions.php");
// $_SESSION["qty"]="1";
?>
<html>
<head>
<title>ONLINE SHOPPING...!</title>
<link rel="stylesheet" href ="styles/style.css" media="all" />
</head>
<body>
<!-- MAIN CONTAINER STARTS FROM HERE-->
<div class="main">
<!-- HEADER STARTS HERE -->
<div class="header">
<a href="index.php"><img id="logo_image" src="images/logo"/></a>
<img id="logo_image" src="images/logo1" style="width: 60%" />
</div>
<!-- HEADER ENDS HERE -->
<!-- NAVIGATION BAR STARTS HERE -->
<div class="menubar">
<ul id="menu">
<li><a href="index.php">HOME</a></li>
<li><a href="all_products.php">ALL PRODUCTS</a></li>
<li><a href="customer/my_account.php">MY ACCOUNTS</a></li>
<li><a href="">SIGN UP</a></li>
<li><a href="cart.php">SHOPPING CART</a></li>
<li><a href="#">CONTACT US</a></li>
</ul>
<div id="form">
<form method="get" action="results.php" enctype="multipart/form-data">
<input type="text" name="user_query" placeholder="Feel Free To Search" />
<input type="submit" name="search" value="search" />
</form>
</div>
</div>
<!-- NAVIGATION BAR ENDS HERE -->
<!-- CONTENTS SECTION START HERE -->
<div class="content">
<div id="sidebar">
<div id="sidebar_title">Categories</div>
<ul id="cats">
<?php getCats(); ?>
</ul>
<div id="sidebar_title">Brands</div>
<ul id="cats">
<?php getBrands(); ?>
</ul>
</div>
<div id="content_area">
<?php cart(); ?>
<div id=shopping_cart>
<span style="float: center; font-size: 18px; padding: 5px; line-height: 40px">
<b style="font-size: 25px;"> Welcome !        </b>
 <i>Total Items:<?php total_items(); ?> </i>  <b>Total Price:</b><?php total_price(); ?> 
<a href="index.php" style="color: yellow; text-decoration: none "><i>Back to </i><b>Home  </b></a>
<!--   used for creating space -->
<?php
if(!isset($_SESSION['customer_email']))
{
echo "<a href='checkout.php' style='color:red; text-decoration:none;'>Login</a>";
}
else
{
echo "<a href='logout.php' style='color:red; text-decoration:none'>Logout</a>";
}
?>
</span>
</div>
<div id="products_box">
<br>
<form action="" method="post" enctype="multipart/form-data">
<table align="center" width="700" >
<tr style="color: blue">
<th>Remove</th>
<th>Product(s)</th>
<th>Quantity</th>
<th>Total Price</th>
</tr>
<?php
$total=0;
global $con;
$ip=getIp();
$sel_price="select * from cart where ip_add='$ip'";
$run_price=mysqli_query($con,$sel_price);
while($p_price=mysqli_fetch_array($run_price))
{
$pro_id=$p_price['p_id'];
global $qty; // for test purpose
$qty=$p_price['qty']; //for test purpose
$pro_price="select * from products where product_id='$pro_id'";
$run_pro_price=mysqli_query($con,$pro_price);
while($pp_price=mysqli_fetch_array($run_pro_price))
{
$product_price=array($pp_price['product_price']);
$product_title=$pp_price['product_title'];
$product_image=$pp_price['product_image'];
$single_price=$pp_price['product_price'];
$values=array_sum($product_price);
$total +=$values;
//echo " ₹ $total";
?>
<tr align="center">
<td><br><br><br><input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?>"></td>
<td><br><?php echo "$product_title"; ?><br>
<img src="admin_area/product_images/<?php echo "$product_image" ?>" width="80" height="80" />
</td>
<td >
<br><br><br>
<input type="number" name="qty" min="1" size="" value="<?php echo 'SESSION["qty"]'; ?>" />
</td>
<?php
if(isset($_POST['update_cart'])) // used for updating quantity in the cart table.
{
$qty=$_POST['qty'];
$update_qty="update cart set qty='$qty'";
$run_qty=mysqli_query($con,$update_qty);
$_SESSION['qty']=$qty;
(int)$total=(int)$total* (int)$qty;
(int)$single_price=(int)$single_price* (int)$qty;
}
?>
<td><br><br><br><?php echo "₹ $single_price"; ?><br></td>
</tr>
<?php } } ?>
<tr align="center">
<td align="right" colspan="3"><br><br><br><b>Sub Total: </b></td>
<td ><br><br><br><?php echo " ₹ $total"; ?></td>
</tr>
<tr align="center">
<td><br><input type="submit" name="update_cart" value="Update Cart"></td>
<td><br><input type="submit" name="continue" value="Continue Shopping"></td>
<td><br><button ><a href="checkout.php" style="text-decoration: none; color:black;">Checkout</a></button></td>
</tr>
</table>
</form>
<?php
//function updatecart()
{
global $con; // used for removing the item from cart
$ip=getIp();
if(isset($_POST['update_cart']))
{
if(isset($_POST['remove']))
{
foreach ($_POST['remove'] as $remove_id)
{
$delete_product= "delete from cart where p_id='$remove_id' and ip_add='$ip'";
$run_delete=mysqli_query($con,$delete_product) or die("query didn't worked");
if($run_delete)
{
echo "<script> window.open('cart.php','_self')</script>";
}
}
}
}
if(isset($_POST['continue'])) // used for redirecting to main page(index.php) from the cart page(cart.php).
{
echo "<script>window.open('index.php','_self')</script>";
}
//echo @$up_cart=updatecart();
}
?>
</div>
</div>
</div>
<!-- CONTENTS SECTION ENDS HERE -->
<div id="footer">
<h2 style="text-align: center;padding-top: 10px ">© By ASHUTOSH RAJ</h2>
</div>
</div>
<!-- MAIN CONTAINER ENDS HERE-->
</body>
</html>