35607-vm/_handle_delete_product.php
Flatlogic Bot 9b5a06451f SInarKasih
2025-11-10 04:11:47 +00:00

31 lines
740 B
PHP

<?php
require_once __DIR__ . '/db/config.php';
// Check if ID is provided
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
header('Location: products.php?error=invalid_id');
exit;
}
$id = $_GET['id'];
// Optional: Add a confirmation step here in a real application
try {
$stmt = db()->prepare('DELETE FROM products WHERE id = ?');
$stmt->execute([$id]);
// Check if any row was deleted
if ($stmt->rowCount() > 0) {
header('Location: products.php?status=deleted');
} else {
header('Location: products.php?error=not_found');
}
exit;
} catch (PDOException $e) {
// Handle DB error
// error_log($e->getMessage());
header('Location: products.php?error=db');
exit;
}