-
Notifications
You must be signed in to change notification settings - Fork 0
/
product.php
118 lines (99 loc) · 4.21 KB
/
product.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
<?php require_once('config.php'); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Husky Market</title>
<link rel="stylesheet" href="css/product.css">
</head>
<body>
<header>
<nav>
<div class="logo">
<a href="index.html"><img src="img/huskylogo.png" alt="Husky Market"></a>
</div>
<div class="nav-links">
<ul>
<li><a href="product.php">Products</a></li>
<li><a href="#">Orders</a></li>
<li><a href="about.html">About</a></li>
<li><a href="review_Admin.php">Custormer Infor</a></li>
<li><a href="history_Order.php">History Order</a></li>
<li><a href="inventory.php">Inventory</a></li>
<li><a href="track_shipping.php">Shipping</a></li>
</ul>
</div>
<div class="nav-buttons" id="nav-buttons">
<a href="cart.php" id="cart-button">
<img src="img/cart-icon.png" alt="Cart" width="20" height="20">
</a>
<a href="login.html" class="sign-in" id="button1">Sign in</a>
<a href="signup.html" class="sign-up" id="button2">Sign up</a>
<a href="#" style="display:none;" id="manage-button">Manage Account</a>
<a href="#" id="logout-button" style="display:none;">Log Out</a>
</div>
</nav>
</header>
<div class="row">
<div class="content">
<?php
$conn = new mysqli(DBHOST, DBUSER, DBPASS, DBNAME);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Build the SQL query to get all products grouped by product_type
$sql = "SELECT * FROM PRODUCT GROUP BY Product_type ORDER BY Product_type ASC";
// Execute the query and get the result
$result = $conn->query($sql);
// Check if any products were found
if ($result->num_rows > 0) {
// Display each product type and its products
while($row = $result->fetch_assoc()) {
echo "<h2 >" . $row["Product_type"] . "</h2>";
echo "<div class='products'>";
// Build the SQL query to get the products of the selected type
$type = $row["Product_type"];
$sql_products = "SELECT * FROM PRODUCT WHERE Product_type='$type'";
$result_products = $conn->query($sql_products);
// Display each product as a card
while($row_products = $result_products->fetch_assoc()) {
echo "<a href='add_to_cart.php?product_id=" . $row_products["Product_id"] . "' class='card' onclick='return confirm(\"Are you sure you want to add " . $row_products["Product_name"] . " to your cart?\")'>
<h3>" . $row_products["Product_name"] . "</h3>
<p class='description'>" . $row_products["Description"] . "</p>
<p class='price'>$" . $row_products["Price"] . "</p>
</a>";
}
echo "</div>";
}
} else {
echo "<p>No products found.</p>";
}
// Close the database connection
$conn->close();
?>
</div>
</div>
<footer>
<p>© 2023 Husky Market. All rights reserved.</p>
</footer>
<script>
// Check if the user is logged in // Set the session storage item to false if it hasn't been set yet
if (!sessionStorage.getItem("loggedIn")) {
sessionStorage.setItem("loggedIn", "false");
}
if (sessionStorage.getItem("loggedIn") === "true") {
// User is logged in, show the user management icon
document.getElementById("button1").style.display = "none";
document.getElementById("button2").style.display = "none";
document.getElementById('manage-button').style.display = 'inline-block';
document.getElementById('logout-button').style.display = 'inline-block';
}
const logoutLink = document.getElementById('logout-button');
logoutLink.addEventListener('click', () => {
sessionStorage.removeItem('loggedIn');
window.location.href = 'index.html';
});
</script>
</body>
</html>