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

$nama =strtoupper($_POST['nama']);
$kadPengenalan =$_POST['noKadPengenalan'];
$noTel =$_POST['noTel'];
$email =strtoupper($_POST['email']);


	if($nama =="" || $kadPengenalan == "" || $noTel =="" ||  $email == "" )
	{
		mysqli_commit($conn);
		echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
		echo "window.location.href = '../daftarPemandu.php';</script>";
		exit;
		
	}
	else
	{
		$sql="SELECT `pemanduID` FROM `pemandu` WHERE `pemanduID`='$kadPengenalan'";
		$fetch = mysqli_query($conn,$sql);
		$row = mysqli_num_rows($fetch);
		
		if($row == 1)
		{
			echo "<script>alert('Pendaftaran gagal. No. Kad Pengenalan sudah didaftarkan!');";
			echo "window.location.href = '../daftarPemandu.php';</script>";
			exit;
		}
		else
		{
			
			$query="INSERT INTO `pemandu` (`pemanduID`,`nama_pemandu`,`noTel`,`email`)
			VALUES ('".$kadPengenalan."','".$nama."','".$noTel."','".$email."')";
			$strQuery = mysqli_query($conn,$query);
			
			if($strQuery) 
				{
					echo "<script>alert('Pendaftaran berjaya!');";
					echo "window.location.href = '../daftarPemandu.php';</script>";
					exit;					
				}
				else
				{
					mysqli_commit($conn);
					echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
					echo "window.location.href = '../daftarPemandu.php';</script>";
					exit;
				}
		}
		
		
		
	}
?>

