-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.php
81 lines (74 loc) · 3.57 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
<?php
require("includes/common.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>E-Store|Cart</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" type="text/css">
<script type="text/javascript" src="bootstrap/js/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="css/css.css" type="text/css">
</head>
<body style="padding-top: 50px;">
<!-- Header -->
<?php
include 'includes/header.php';
?>
<!--Header end-->
<div class="container">
<div class="row row_style2">
<div class="col-sm-10 col-sm-offset-1">
<table class="table table-striped">
<!--show table only if there are items added in the cart-->
<?php
$sum = 0;
$user_id = $_SESSION['user_id'];
$query = "SELECT items.price AS Price, items.id, items.name AS Name FROM users_items JOIN items ON users_items.item_id = items.id WHERE users_items.user_id='$user_id' and status='Added to cart'";
$result = mysqli_query($con, $query)or die(mysqli_error($con));
if (mysqli_num_rows($result) >= 1) {
?>
<thead>
<tr>
<th>Item Number</th>
<th>Item Name</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_array($result)) {
$sum+= $row["Price"];
$id="";
$id .= $row["id"] . ",";
echo "<tr>
<td>" . "#" . $row["id"] . "</td>
<td>" . $row["Name"] . "</td>
<td>Rs " . $row["Price"] . "</td>
<td><a href='cart-remove.php?id={$row['id']}' class='remove_item_link'> X </a></td>
</tr>";
}
$id = rtrim($id, ",");
echo "<tr>
<td></td>
<td>Total</td>
<td>Rs " . $sum . "</td>
<td><a href='success.php?itemsid=".$id."'class='btn btn-primary'>Confirm Order</a></td>
</tr>";
?>
</tbody>
<?php
} else {
echo "<center><h2><br>Add items to the cart first!</h2><p><a href='products.php'>click here</a> to explore products</p></center>";
}
?>
<?php
?>
</table>
</div>
</div>
</div>
</body>
</html>