65 lines
2.6 KiB
PHP
65 lines
2.6 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
|
|
$product_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
|
|
if ($product_id === 0) {
|
|
$_SESSION['error_message'] = "ID de producto no válido.";
|
|
header("Location: productos.php");
|
|
exit();
|
|
}
|
|
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM productos WHERE id = ?");
|
|
$stmt->execute([$product_id]);
|
|
$product = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$product) {
|
|
$_SESSION['error_message'] = "Producto no encontrado.";
|
|
header("Location: productos.php");
|
|
exit();
|
|
}
|
|
?>
|
|
|
|
<div class="container-fluid">
|
|
<div class="d-sm-flex justify-content-between align-items-center mb-4">
|
|
<h3 class="text-dark mb-0">Editar Producto</h3>
|
|
</div>
|
|
|
|
<div class="card shadow mb-4">
|
|
<div class="card-header py-3">
|
|
<h6 class="m-0 font-weight-bold text-primary">Detalles del Producto</h6>
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="handle_editar_producto.php" method="post">
|
|
<input type="hidden" name="id" value="<?php echo htmlspecialchars($product['id']); ?>">
|
|
|
|
<div class="mb-3">
|
|
<label for="nombre" class="form-label">Nombre del Producto</label>
|
|
<input type="text" class="form-control" id="nombre" name="nombre" value="<?php echo htmlspecialchars($product['nombre']); ?>" required>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="descripcion" class="form-label">Descripción</label>
|
|
<textarea class="form-control" id="descripcion" name="descripcion" rows="3"><?php echo htmlspecialchars($product['descripcion']); ?></textarea>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col-md-6 mb-3">
|
|
<label for="costo" class="form-label">Precio de Compra</label>
|
|
<input type="number" class="form-control" id="costo" name="costo" step="0.01" value="<?php echo htmlspecialchars($product['costo']); ?>" required>
|
|
</div>
|
|
<div class="col-md-6 mb-3">
|
|
<label for="precio_venta" class="form-label">Precio de Venta</label>
|
|
<input type="number" class="form-control" id="precio_venta" name="precio_venta" step="0.01" value="<?php echo htmlspecialchars($product['precio_venta']); ?>" required>
|
|
</div>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Guardar Cambios</button>
|
|
<a href="productos.php" class="btn btn-secondary">Cancelar</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|