-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts.php
42 lines (37 loc) · 1.11 KB
/
products.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
<!DOCTYPE html>
<html>
<head>
<title>Product Listing</title>
</head>
<body>
<h1>Product Listing</h1>
<?php
// Connect to the database (Replace with your connection code)
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "your_database_name";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve all products from the database
$sql = "SELECT * FROM products";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Display product data in a list
echo "<ul>";
while ($row = $result->fetch_assoc()) {
echo "<li><a href='product_details.php?id=" . $row['id'] . "'>" . $row['product_name'] . "</a></li>";
// Display other product information as needed
}
echo "</ul>";
} else {
echo "<p>No products found.</p>";
}
// Close the database connection
$conn->close();
?>
</body>
</html>