<?php
include '../../connect.php';
session_start();

// Validasi parameter GET
if (!isset($_GET['tempahanID']) || empty($_GET['tempahanID'])) {
    echo "<script>alert('Ralat: ID tempahan tidak sah.'); window.location.href = '../DashboardKenderaan.php';</script>";
    exit;
}

$tempahanID = $_GET['tempahanID'];

$query = "SELECT tempahanID FROM tempahan_kenderaan WHERE tempahanID='".$tempahanID."'";
$strQuery = mysqli_query($conn,$query);

	if($strQuery)
	{
			
		$query= "UPDATE `tempahan_kenderaan` SET status='BATAL' WHERE tempahanID='".$tempahanID."'";
		$strQuery = mysqli_query($conn,$query);	
		
		if($strQuery) 
		{
			$sql = "SELECT * FROM tempahan_kenderaan WHERE tempahanID='$tempahanID'";
			$result = mysqli_query($conn,$sql);
			$row = mysqli_fetch_array($result);
			
			echo "<script>";
			echo "window.location.href = '../DashboardKenderaan.php';</script>";
			exit;
		}
		else
		{
			echo 'MySQL Error: ' . mysqli_error($conn);
			exit;
		}
		
	}
	else
	{
				echo 'MySQL Error: ' . mysqli_error($conn);
				exit;
	}
?>