-
Notifications
You must be signed in to change notification settings - Fork 1
/
cart.php
145 lines (130 loc) · 4.69 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
<?php
include('header.php');
include('conn.php'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
</head>
<style>
.cart-header {
width: 25%;
align-self: center;
padding: 5px;
}
.path a:hover {
color: gray;
text-decoration: none;
}
.path a {
color: darkgray;
}
.path .less {
color: gray;
font-weight: bolder;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;
}
</style>
<body>
<div class="container-fluid path">
<a href="home.php">Home</a> <label for="" class="less">></label>
<a href="products.php">Products</a><label for="" class="less">></label>
<a href="">Cart</a>
</div>
<div class="container mt-5 mb-5">
<div class="row">
<table class="table table-striped table-borderless px-8">
<thead>
<tr class="row bg-primary">
<th class="col-2">#</th>
<th class="col-3">Name</th>
<th class="col-1">Quantity</th>
<th class="col-2">Price</th>
<th class="col-2">Total</th>
</tr>
</thead>
<tbody>
<?php
if (isset($_SESSION['email'])) {
$final = 0;
// $id = $_GET['ProductID'];
$uid = $_SESSION['id'];
// $sql1 = "INSERT INTO `cartdetails`(`ProductID`, `UserID`) VALUES ($id,$uid)";
// mysqli_query($conn,$sql1);
// $sql = "SELECT * FROM products inner join cartdetails on products.ProductID=cartdetails.ProductID Where cartdetails.UserID=$uid";
$sql = "SELECT * FROM cartdetails WHERE UserID=$uid";
$Count = 1;
$result = mysqli_query($conn, $sql);
if (!$result) {
exit;
}
if ($result->num_rows == 0) {
// return null;
echo "NO data found";
exit;
} else {
$rowcount = $result->num_rows;
while ($pdts = $result->fetch_assoc()) {
$total = ($pdts['ProductQuantity']) * ($pdts['ProductPrice']);
$final += $total;
if ($Count < $rowcount) {
?>
<tr class="row">
<th class="col-2" scope="row"><?php echo $Count++; ?></th>
<!-- <td class="col-3">#</td> -->
<td class="col-3"><?php echo $pdts["ProductName"] ?></td>
<td class="col-1"><?php echo $pdts["ProductQuantity"] ?></td>
<td class="col-2"><i class="fas fa-rupee-sign"></i> <?php echo $pdts["ProductPrice"] ?></td>
<td class="col-1"><i class="fas fa-rupee-sign"></i> <?php echo $total; ?></td>
<td class="col-3">
<a class="col-1" href='cartitemdelete.php?id=<?php echo $pdts["ProductID"]; ?>'>Remove</a>
<a class="col-1" href='cartitemedit.php?id=<?php echo $pdts["ProductID"]; ?>'>Update</a>
<button class="btn btn-success" onclick="window.location='http://localhost/code/SEM%206/testing/bs4/buy.php?ProductID=<?= $pdts['ProductID']; ?>'" type="submit">Buy Now</button>
</td>
</tr>
<?php
} else {
?>
<tr class="row">
<th class="col-2" scope="row"><?php echo $Count++; ?></th>
<!-- <td class="col-3">#</td> -->
<td class="col-3"><?php echo $pdts["ProductName"] ?></td>
<td class="col-1"><?php echo $pdts["ProductQuantity"] ?></td>
<td class="col-2"><i class="fas fa-rupee-sign"></i> <?php echo $pdts["ProductPrice"] ?></td>
<td class="col-1"><i class="fas fa-rupee-sign"></i> <?php echo $total; ?></td>
<td class="col-3">
<a class="col-1" href='cartitemdelete.php?id=<?php echo $pdts["ProductID"]; ?>'>Remove</a>
<a class="col-1" href='cartitemedit.php?id=<?php echo $pdts["ProductID"]; ?>'>Update</a>
<button class="btn btn-success" onclick="window.location='http://localhost/code/SEM%206/testing/bs4/buy.php?ProductID=<?= $pdts['ProductID']; ?>'" type="submit">Buy Now</button>
</td>
<tr class="row" style="background-color: whitesmoke;">
<td class="col-6"></td>
<td class="col-2"><strong>Total:-</strong></td>
<td class="col-1"><i class="fas fa-rupee-sign"></i> <?php echo $final; ?></td>
</tr>
</tbody>
</table>
<div class="col-5" align="right">
<!-- Total:- <i class="fas fa-rupee-sign"></i> <?php echo $final; ?> -->
</div>
<div class="col-7"><input class="btn btn-success col-12" type="submit" onclick="window.location='buy.php'" ; value="Buy Now"></div>
</div>
<?php
}
}
}
} else {
// header("Location: login.php");
?>
<script>
alert('please login first');
location.replace("login.php");
</script>
<?php
}
?>
</div>
</body>
<?php include('footer.php') ?>
</html>