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

$plat =strtoupper($_POST['plat']);
$model =strtoupper($_POST['model']);


	if($plat =="" || $model == "" )
	{
		mysqli_commit($conn);
		echo "<script>alert('Sila lengkapkan maklumat kenderaan. ');";
		echo "window.location.href = '../daftarPemandu.php';</script>";
		exit;
		
	}
	else
	{
		$sql="SELECT `kenderaanID` FROM `kenderaan` WHERE `kenderaanID`='$plat'";
		$fetch = mysqli_query($conn,$sql);
		$row = mysqli_num_rows($fetch);
		
		if($row == 1)
		{
			echo "<script>alert('Pendaftaran gagal. No. plat sudah didaftarkan!');";
			echo "window.location.href = '../daftarKenderaan.php';</script>";
			exit;
		}
		else
		{
			
			$query="INSERT INTO `kenderaan` (`kenderaanID`,`jenisKereta`)
			VALUES ('".$plat."','".$model."')";
			$strQuery = mysqli_query($conn,$query);
			
			if($strQuery) 
				{
					echo "<script>alert('Pendaftaran berjaya!');";
					echo "window.location.href = '../daftarKenderaan.php';</script>";
					exit;					
				}
				else
				{
					mysqli_commit($conn);
					echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
					echo "window.location.href = '../daftarKenderaan.php';</script>";
					exit;
				}
		}
		
		
		
	}
?>

