-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_cart.php
164 lines (128 loc) · 6.83 KB
/
view_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
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8">
<title>NIKE PRELOVED STORE</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="images/nike.png" rel="icon" type="image/png">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/v4-shims.css">
</head>
<body>
<!--navigation-->
<div class="container">
<nav>
<input type="checkbox" id="nav" class="hidden">
<label for="nav" class="nav-btn">
<i></i>
<i></i>
<i></i>
</label>
<div class="nav-wrapper">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="products.php">PRODUCTS</a></li>
<li><a href="contact.html">CONTACT</a></li>
<li><a href="view_cart.php"><i class="fas fa-shopping-cart"></i></a></li>
</ul>
</div>
</nav>
</div>
<div id="whole">
<br/>
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<?php
if(isset($_SESSION['message']))
{
?>
<div class="alert alert-info text-center">
<?php echo $_SESSION['message']; ?>
</div>
<?php
unset($_SESSION['message']);
}
?>
<form method="POST" action="save_cart.php">
<h1>Order List</h1>
<table class="table table-bordered table-striped">
<thead>
<th></th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Subtotal</th>
</thead>
<tbody>
<?php $total=0;
if(!empty($_SESSION['cart']))
{
//connection
$conn = new mysqli('localhost', 'root', '', 'nikestore');
//create array of initial qty which is 1
$index = 0;
if(!isset($_SESSION['qty_array']))
{
$_SESSION['qty_array'] = array_fill(0, count($_SESSION['cart']), 1);
}
$sql = "SELECT * FROM products WHERE id IN (".implode(',',$_SESSION['cart']).")";
$query = $conn->query($sql);
while($row = $query->fetch_assoc())
{
?>
<tr>
<td>
<a href="delete_item.php?id=<?php echo $row['id']; ?>&index=<?php echo $index; ?>" class="btn btn-danger btn-sm">
<span class="glyphicon glyphicon-trash"></span>
</a>
</td>
<td><?php echo $row['name']; ?></td>
<td>$ <?php echo number_format($row['price'], 2); ?></td>
<input type="hidden" name="indexes[]" value="<?php echo $index; ?>">
<td>
<input type="text" class="form-control" value="<?php echo $_SESSION['qty_array'][$index]; ?>" name="qty_<?php echo $index; ?>">
</td>
<td>
$ <?php echo number_format($_SESSION['qty_array'][$index]*$row['price'], 2); ?>
</td>
<?php $total += $_SESSION['qty_array'][$index]*$row['price']; ?>
</tr>
<?php
$index ++;
}
}
else
{
?>
<tr>
<td colspan="4" class="text-center">No Item in Cart</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="right"><b>Total</b></td>
<td><b>$ <?php echo number_format($total, 2); ?></b></td>
</tr>
</tbody>
</table>
<a href="products.php" class="btn btn-primary"><span class="glyphicon glyphicon-arrow-left"></span> Back</a>
<button type="submit" class="btn btn-success" name="save">Save Changes</button>
<a href="clear_cart.php" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> Clear Cart</a>
<a href="checkout.php" class="btn btn-success"><span class="glyphicon glyphicon-check"></span> Checkout</a>
</form>
</div>
</div>
</div>
</div>
<footer>
<!--copyright-->
<div class="copyright"><p>Copyright © 2019 | <strong>NIKE PRELOVED STORE</strong></p></div>
</footer>
</body>
</html>