-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
executable file
·267 lines (171 loc) · 5.99 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
<?php
session_start();
?>
<!DOCTYPE>
<?php
include("functions/functions.php");
?>
<html>
<head>
<title>MY online store</title>
<link rel="stylesheet" href="style.css" media="all">
</head>
<body>
<!--main wrapper starts-->
<div class="main_wrapper">
<!--header wrapper starts-->
<div class="header_wrapper">
<img id="logo" src="images\logo.png">
<img id="banner" src="images\banner2.jpg">
</div>
<!--header wrapper ends-->
<!--menubar starts-->
<div class="menubar">
<ul id="menu">
<li><a href="index.php">Home</a><li>
<li><a href="allproducts.php">All Products</a><li>
<li><a href="register.php">Sign Up</a><li>
<li><a href="cart.php">Shopping Cart</a><li>
<li><a href="contact_us.php">Contact Us</a><li>
</ul>
<div id="form">
<form method="get" action="results.php" enctype="multipart/form-data">
<input id="text" type="text" placeholder="search item" name="user_query">
<input id="search" type="submit" value="Search" name="search">
</form>
</div>
</div>
<!--menubar ends-->
<!--content wrapper starts-->
<div class="content_wrapper">
<div id="sidebar">
<div id="sidebar-title">CATEGORIES</div>
<ul id="cats">
<?php getcats(); ?>
</ul>
<div id="sidebar-title">AUTHORS</div>
<ul id="cats">
<?php getauthor(); ?>
</ul>
</div>
<div id="content_area">
<?php get_cart(); ?>
<div id="shopping_cart">
<span style="float:right;font-size:18px;padding:5px;line-height:35px;">
<?php
if(isset($_SESSION['customer_email']))
{
echo "<b style='color:darkturquoise;font-size:26px'>Welcome:-</b>"." ".$_SESSION['customer_email'];
}
else{
echo "<b>Welcome Guest!!</b>";
}
?>
<?php
if(!isset($_SESSION['customer_email'])){
echo "<a href='checkout.php' style='color:orange;'>Login</a>";
}
else{
echo "<a href='logout.php' style='color:orange;'>Logout</a>";
}
?>
</span>
</div>
<div id='products_box'>
<form action="" method="post" enctype="multipart/form-data">
<table align="center" width="600" bgcolor="skyblue">
<tr align="center" style="font-size:20px;color:green;font-family:cursive" >
<th><b>Remove</b></th>
<th><b>Product(s)</b></th>
<th><b>Quantity</b></th>
<th><b>total Price</b></th>
</tr>
<?php
$total =0;
global $con;
$ip = getIp();
$create_query = "select * from cart where ip_add = '$ip'";
$run_query = mysqli_query($con,$create_query);
while($price = mysqli_fetch_array($run_query)){
$pro_id = $price['pii_id'];
$price_query = "select * from products where p_id = '$pro_id'";
$price_run_query = mysqli_query($con,$price_query);
while($pp_price = mysqli_fetch_array($price_run_query))
{
$final_price = array($pp_price['p_price']);
$product_title = $pp_price['p_title'];
$product_image = $pp_price['p_image'];
$single_price = $pp_price['p_price'];
$product_quantity = $pp_price['p_quantity'];
$values = array_sum($final_price);
$total += $values;
?>
<tr align="center">
<td><input type="checkbox" name= "remove[]" value="<?php echo $pro_id ; ?>" ></td>
<td style="font-size:20px;color:red;font-family:cursive"><?php echo $product_title; ?><br>
<img style="border:2px solid orange" src = "admin_area/product_images/<?php echo $product_image; ?>" width="140" height="120">
</td>
<td><input type="number" size="4" name="qty" value = "<?php echo $_SESSION['qty'] ?>"></td>
<?php
if(isset($_POST['update_cart'])){
$qty = $_POST['qty'];
$qty_query = "update cart
set qty = '$qty'";
$qty_query_run = mysqli_query($con,$qty_query);
$_SESSION['qty'] = $qty;
$total = $total * $qty;
$product_quantity=$product_quantity-$qty
}
?>
<td style="font-size:20px;"><?php echo "$".$single_price;?></td>
</tr>
<?php
}
} ?>
<tr align="right">
<td colspan="5" style="font-size:20px;color:blue;font-family:cursive">Sub Total:</td>
<td style="font-size:20px;"><?php echo "$".$total; ?></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="update_cart" value="Update Cart"></td>
<td><input type="submit" name="continue" value="Continue"></td>
<td><button style='text-decoration:none'><a style='text-decoration:none;color:black' href="checkout.php"> Checkout</a></button></td>
</tr>
</table>
</form>
<?php
function updatecart(){
global $con;
$ip = getIp();
if(isset($_POST['update_cart'])){
foreach($_POST['remove'] as $remove_id)
{
$delete_product ="DELETE FROM cart where pii_id='$remove_id' and ip_add = '$ip'";
$run_delete = mysqli_query($con,$delete_product);
if($run_delete){
echo "<script>
alert('item deleted from the cart');
window.open('cart.php','_self');
</script>";
}
}
}
echo @$up_cart = updatecart();
}
if(isset($_POST['continue']))
{
echo"
<script>window.open('index.php','_self')</script>
";
}
?>
</div>
</div>
</div>
<!--content wrapper ends-->
<div id="footer"><h2>©2017 by www.shopnix.com</h2></div>
</div>
<!--main wrapper ends-->
<?php updatecart(); ?>
</body>
</html>