-
Notifications
You must be signed in to change notification settings - Fork 10
/
cart.php
73 lines (61 loc) · 1.83 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
<?php
if(isset($_POST['submit'])){
foreach($_POST['quantity'] as $key => $val) {
if($val==0) {
unset($_SESSION['cart'][$key]);
}else{
$_SESSION['cart'][$key]['quantity']=$val;
}
}
}
if(isset($_POST['order'])) {
//require_once('repairs.php');
}
?>
<h1>View cart</h1>
<a href="chooseProducts.php?page=products">Go back to products page</a>
<form method="post" action="chooseProducts.php?page=cart">
<table>
<tr>
<th>Stock#</th>
<th>Quantity</th>
<th>Price</th>
<th>Items Price</th>
</tr>
<?php
$conn= mysqli_connect("localhost", "root", "", "compsys");
$sql="SELECT * FROM stock WHERE stock_id IN (";
foreach($_SESSION['cart'] as $id => $value) {
$sql .= $id .",";
}
//$sql[37] = ' ';
$sql=substr($sql, 0, -1) .") ORDER BY stock_id ASC";
//$query=mysql_query($sql);
$res = mysqli_query($conn, $sql);
if (!$res) {
printf("Nothing in the basket: %s\n", "Go back");
exit();
}
$totalprice=0;
while($row = mysqli_fetch_array($res)){
$subtotal = $_SESSION['cart'][$row['stock_id']]['quantity']*$row['price'];
$totalprice += $subtotal;
?>
<tr>
<td><?php echo $row['description'] ?></td>
<td><input type="text" name="quantity[<?php echo $row['stock_id'] ?>]" size="5" value="<?php echo $_SESSION['cart'][$row['stock_id']]['quantity'] ?>" /></td>
<td><?php echo '€' .$row['price'] ?></td>
<td><?php echo '€' .$_SESSION['cart'][$row['stock_id']]['quantity']*$row['price'] ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4">Total Price: <?php echo '€'. $totalprice ?></td>
</tr>
</table>
<br />
<button type="submit" name="submit">Update Cart</button>
</form>
<br />
<p>To remove an item, set it's quantity to 0. </p>