-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedit_product.php
89 lines (75 loc) · 2.28 KB
/
edit_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
<!DOCTYPE html>
<html>
<head>
<title>Admin Dashboard</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>Welcome to the Admin Dashboard!</h1>
<?php
// Connect to the database
include("dbconnect.php");
// Check for errors
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Check if the form has been submitted
if (isset($_POST['submit'])) {
// Retrieve the product details from the form
$id = $_POST['id'];
$name = $_POST['name'];
$description = $_POST['description'];
$price = $_POST['price'];
$available = $_POST['available'];
// Update the product in the database
$sql = "UPDATE product SET name='$name', description='$description', price='$price', available='$available' WHERE id=$id";
$result = mysqli_query($conn, $sql);
// Check for errors
if (!$result) {
die("Error: " . mysqli_error($conn));
}
// Redirect back to the product page
header("Location: admin_product.php");
exit;
}
// Retrieve the product ID from the URL
$id = $_GET['id'];
// Query the database for the product with the specified ID
$sql = "SELECT * FROM product WHERE id=$id";
$result = mysqli_query($conn, $sql);
// Check for errors
if (!$result) {
die("Error: " . mysqli_error($conn));
}
// Retrieve the product details from the database
$row = mysqli_fetch_assoc($result);
$name = $row['name'];
$description = $row['description'];
$price = $row['price'];
$available = $row['available'];
// Close the database connection
mysqli_close($conn);
?>
<!-- Display the form for editing the product details -->
<form method="post">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<label>Name:</label>
<input type="text" name="name" value="<?php echo $name; ?>">
<label>Description:</label>
<textarea name="description"><?php echo $description; ?></textarea>
<label>Price:</label>
<input type="number" name="price" value="<?php echo $price; ?>">
<label>Available:</label>
<input type="number" name="available" value="<?php echo $available; ?>">
<input type="submit" name="submit" value="Save Changes">
</form>
</body>
</html>