-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_product.php
More file actions
125 lines (111 loc) · 5.66 KB
/
edit_product.php
File metadata and controls
125 lines (111 loc) · 5.66 KB
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
119
120
121
122
123
124
125
<?php
session_start();
include('config.php');
// Only allow admin users to access this page
if (!isset($_SESSION['user_role']) || $_SESSION['user_role'] !== 'admin') {
header("Location: products.php");
exit();
}
// Check for the product ID in the query string
if (!isset($_GET['id'])) {
header("Location: products.php");
exit();
}
$product_id = $_GET['id'];
// Fetch the product details
$sql = "SELECT * FROM products WHERE id='$product_id'";
$result = mysqli_query($conn, $sql);
if (!$result || mysqli_num_rows($result) == 0) {
header("Location: products.php");
exit();
}
$product = mysqli_fetch_assoc($result);
mysqli_close($conn);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Product - Honey E-Commerce</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body { background-color: #f8f9fa; }
</style>
</head>
<body>
<!-- Navigation Bar -->
<nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="index.php">Honey E-Commerce</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="products.php">Back to Products</a>
</li>
</ul>
</div>
</div>
</nav>
<!-- Edit Product Form -->
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card shadow">
<div class="card-header bg-primary text-white">
<h3 class="text-center mb-0">Edit Product</h3>
</div>
<div class="card-body">
<form action="update_product.php" method="POST" enctype="multipart/form-data">
<!-- Hidden field to store product ID -->
<input type="hidden" name="product_id" value="<?php echo htmlspecialchars($product_id); ?>">
<div class="mb-3">
<label for="name" class="form-label">Product Name</label>
<input type="text" class="form-control" id="name" name="name"
value="<?php echo htmlspecialchars($product['name']); ?>" required>
</div>
<div class="mb-3">
<label for="price" class="form-label">Price ($)</label>
<input type="number" class="form-control" id="price" name="price"
value="<?php echo htmlspecialchars($product['price']); ?>" step="0.01" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description" rows="4" required><?php echo htmlspecialchars($product['description']); ?></textarea>
</div>
<div class="mb-3">
<label for="stock" class="form-label">Stock</label>
<input type="number" class="form-control" id="stock" name="stock"
value="<?php echo htmlspecialchars($product['stock']); ?>" required>
</div>
<div class="mb-3">
<label class="form-label">Current Product Image</label><br>
<?php if (!empty($product['image'])): ?>
<img src="<?php echo htmlspecialchars($product['image']); ?>" alt="Product Image"
style="width:200px; height:200px; object-fit:cover;">
<?php else: ?>
<p>No Image Available</p>
<?php endif; ?>
</div>
<div class="mb-3">
<label for="image" class="form-label">Update Product Image (optional)</label>
<input type="file" class="form-control" id="image" name="image" accept="image/*">
<small class="form-text text-muted">Leave blank if you do not want to change the image.</small>
</div>
<div class="text-center">
<button type="submit" name="update" class="btn btn-primary">Update Product</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>