-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.php
59 lines (50 loc) · 2.04 KB
/
edit.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
<!DOCTYPE html>
<html>
<head>
<title>Edit Product</title>
</head>
<body>
<h1>Edit Product</h1>
<?php
// Check if an ID is provided for editing (Replace with your connection code)
$product_id = $_GET['id'] ?? null;
if (!$product_id) {
echo "<p>No product ID provided for editing.</p>";
} else {
// Connect to the database (Replace with your connection code)
$servername = "localhost";
$username = "admin";
$password = "Nt4MV6m8csRx26JRXHMq8oRWDCVodPDRHcQ5dhoBrRWcYaC648NYFzvjUjfeDEWsoMXGapFzHspkXUR9WuFuc8i3Nsc!";
$dbname = "swiftpeakweb";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve product data based on the provided ID
$sql = "SELECT * FROM products WHERE id = $product_id";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
?>
<form method="post" action="edit_process.php">
<!-- Input fields for editing product information -->
<input type="hidden" name="id" value="<?php echo $row['id']; ?>">
<label for="name">Product Name:</label>
<input type="text" name="name" value="<?php echo $row['product_name']; ?>"><br>
<label for="description">Description:</label><br>
<textarea name="description" rows="5"><?php echo $row['description']; ?></textarea><br>
<label for="price">Price:</label>
<input type="text" name="price" value="<?php echo $row['price']; ?>"><br>
<button type="submit" name="submit">Update</button>
</form>
<?php
} else {
echo "<p>Product not found.</p>";
}
// Close the database connection
$conn->close();
}
?>
</body>
</html>