39 lines
1.1 KiB
PHP
39 lines
1.1 KiB
PHP
<?php
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
echo "<div class='alert alert-danger'>Invalid product ID.</div>";
|
|
return;
|
|
}
|
|
|
|
$product_id = $_GET['id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM products WHERE id = ?");
|
|
$stmt->execute([$product_id]);
|
|
$product = $stmt->fetch();
|
|
} catch (PDOException $e) {
|
|
echo "<div class='alert alert-danger'>Database error: " . htmlspecialchars($e->getMessage()) . "</div>";
|
|
return;
|
|
}
|
|
|
|
if (!$product) {
|
|
echo "<div class='alert alert-danger'>Product not found.</div>";
|
|
return;
|
|
}
|
|
?>
|
|
|
|
<h1 class="h3 mb-4">Edit Product</h1>
|
|
|
|
<?php
|
|
if (isset($_SESSION['error_message'])) {
|
|
echo '<div class="alert alert-danger alert-dismissible fade show" role="alert">' . htmlspecialchars($_SESSION['error_message']) . '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>';
|
|
unset($_SESSION['error_message']);
|
|
}
|
|
?>
|
|
|
|
<div class="card shadow-sm">
|
|
<div class="card-body">
|
|
<?php include __DIR__ . '/partials/product_form.php'; // The form is included here ?>
|
|
</div>
|
|
</div>
|