64 lines
2.4 KiB
PHP
64 lines
2.4 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/auth.php';
|
|
require_login();
|
|
|
|
require_once __DIR__ . '/db/config.php';
|
|
require_once __DIR__ . '/includes/header.php';
|
|
|
|
// Check if ID is provided
|
|
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
|
|
// Redirect or show an error
|
|
header('Location: products.php');
|
|
exit;
|
|
}
|
|
|
|
$id = $_GET['id'];
|
|
|
|
// Fetch the product
|
|
$stmt = db()->prepare('SELECT * FROM products WHERE id = ?');
|
|
$stmt->execute([$id]);
|
|
$product = $stmt->fetch();
|
|
|
|
if (!$product) {
|
|
// Redirect or show an error
|
|
header('Location: products.php');
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<h1 class="h2">Edit Product</h1>
|
|
</div>
|
|
|
|
<form action="_handle_edit_product.php" method="POST">
|
|
<input type="hidden" name="id" value="<?php echo $product['id']; ?>">
|
|
<div class="row">
|
|
<div class="col-md-6 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="col-md-6 mb-3">
|
|
<label for="sku" class="form-label">SKU (Stock Keeping Unit)</label>
|
|
<input type="text" class="form-control" id="sku" name="sku" value="<?php echo htmlspecialchars($product['sku']); ?>">
|
|
</div>
|
|
</div>
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="category" class="form-label">Category</label>
|
|
<input type="text" class="form-control" id="category" name="category" value="<?php echo htmlspecialchars($product['category']); ?>">
|
|
</div>
|
|
<div class="col-md-3 mb-3">
|
|
<label for="price" class="form-label">Price (Rp)</label>
|
|
<input type="number" class="form-control" id="price" name="price" step="0.01" value="<?php echo htmlspecialchars($product['price']); ?>" required>
|
|
</div>
|
|
<div class="col-md-3 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>
|
|
<button type="submit" class="btn btn-primary">Update Product</button>
|
|
<a href="products.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|