<?php
session_start();
include 'db.php';

if (!isset($_SESSION['username'])) {
    header('Location: index.php');
    exit;
}

if (isset($_GET['no_id'])) {
    $id = (int) $_GET['no_id'];

    $stmt = $conn->prepare("DELETE FROM kendaraan WHERE no_id = ?");
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        echo "<script>alert('Data kendaraan berhasil dihapus!'); window.location='tambah_kendaraan.php';</script>";
    } else {
        echo "<script>alert('Data kendaraan gagal dihapus!'); window.location='tambah_kendaraan.php';</script>";
    }

    $stmt->close();
    $conn->close();
} else {
    header('Location: tambah_kendaraan.php');
    exit;
}
?>
