-
Notifications
You must be signed in to change notification settings - Fork 6
/
categoryview.php
76 lines (63 loc) · 1.99 KB
/
categoryview.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
<?php
ob_start();
session_start();
include('connections/localhost.php');
?>
<?php include("includes/header.php"); ?>
<?php include("includes/navbar.php"); ?>
<body>
<h2 class="h-auto"> Product List</h2>
<?php
global $conn;
if (!isset($_GET['category']) || empty(trim($_GET['category']))) {
header("location: categories.php");
} else {
$category = htmlspecialchars(stripslashes(strip_tags($_GET['category'])));
$category = mysqli_real_escape_string($conn, $category);
$_SESSION['category'] = $category; // for later use.
$query = "SELECT * FROM `products` WHERE category = '$category'";
$result = mysqli_query($conn, $query) or die(mysqli_error($conn));
$count = mysqli_num_rows($result);
if ($count == 0) exit("No Products Found of this Category."); ?>
<div class="container-grid">
<?php
while ($row = mysqli_fetch_array($result)) {
?>
<div class="item-box">
<!-- START OF single item box -->
<div> <img src="<?php echo basename('uploads/') . "/" . $row['product_image']; ?>" width="200" height="200"> </div>
<div><?php echo $row['productname'] ?> </div>
<div>
<p style="color: crimson"><strong><?php echo "CNY " . $row['price'] ?></strong> </p>
</div>
<?php
if (!isset($_SESSION['email'])) {
//if user is NOT logged in
echo '<div><button class="addtocartbtn" onClick="taketoLogin()">Add to Cart<button></div>';
} else {
?>
<div> <a href="addtocart.php?id=<?php echo $row['productID'] ?>"><button class="addtocartbtn">Add to Cart</button></a></div>
<?php } ?>
</div>
<!-- END OF single item box -->
<?php
}
}
?>
</div>
</div>
<br>
<?php include("includes/footer.php"); ?>
<br>
<script type="application/javascript">
function taketoLogin() {
//this JS takes someone to Login page if not logged in.
window.alert("Please login first!");
window.location.replace("login.php");
}
</script>
</br>
</br>
<?php include("includes/footer.php"); ?>
</body>
</html>