-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_product.php
88 lines (74 loc) · 2.3 KB
/
admin_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
<!DOCTYPE html>
<html>
<head>
<title>Admin Products</title>
</head>
<body>
<nav>
<ul>
<li><a href="admin_dashboard.php">Home</a></li>
<li><a href="admin_products.php">Products</a></li>
<li><a href="admin_orders.php">Manage Orders</a></li>
<li><a href="admin_users.php">Manage Users</a></li>
<li><a href="logout.php">Logout</a></li>
</ul>
</nav>
<h1>Manage Products</h1>
<!-- Section 1: Create new product -->
<h2>Create New Product</h2>
<form action="create_product.php" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required><br>
<label for="description">Description:</label>
<textarea id="description" name="description" required></textarea><br>
<label for="price">Price:</label>
<input type="number" id="price" name="price" min="0" step="0.01" required><br>
<label for="available">Available:</label>
<input type="number" id="available" name="available" min="0" step="0.01" required><br>
<label for="image">Image:</label>
<input type="file" id="image" name="image" min="0" step="0.01" required><br>
<input type="submit" value="Create Product">
</form>
<!-- Section 3: List of product details -->
<h2>List of Products</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th>Available</th>
<th>Actions</th>
</tr>
<!-- Your PHP code to retrieve and display product details goes here -->
<?php
// Connect to the database
include("dbconnect.php");
// Check for errors
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Query the database for products
$sql = "SELECT * FROM product";
$result = mysqli_query($conn, $sql);
// Check for errors
if (!$result) {
die("Error: " . mysqli_error($conn));
}
// Loop through the results and display each product in a table row
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['price'] . "</td>";
echo "<td>" . $row['available'] . "</td>";
echo "<td><a href='edit_product.php?id=" . $row['id'] . "'>Edit</a> | <a href='delete_product.php?id=" . $row['id'] . "'>Delete</a></td>";
echo "</tr>";
}
// Close the database connection
mysqli_close($conn);
?>
</table>
</body>
</html>