29 lines
644 B
PHP
29 lines
644 B
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// If the user is not logged in, redirect to the login page.
|
|
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
|
|
header('Location: admin.php');
|
|
exit;
|
|
}
|
|
|
|
$id = $_GET['id'] ?? null;
|
|
if (!$id) {
|
|
header('Location: admin_vehicles.php');
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("DELETE FROM vehicles WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
|
|
header("Location: admin_vehicles.php?success=3");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
// Redirect with an error message
|
|
header("Location: admin_vehicles.php?error=db");
|
|
exit;
|
|
}
|