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

$nama =strtoupper($_POST['nama']);
$kadPengenalan =$_POST['kadPengenalan'];
$password =$_POST['password'];
$jawatan =strtoupper($_POST['jawatan']);
$bahagian =$_POST['bahagian'];


	if($nama =="" || $kadPengenalan == "" || $password =="" ||  $jawatan == "" ||$bahagian == "")
	{
		mysqli_commit($conn);
		echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
		echo "window.location.href = '../registration.php';</script>";
		exit;
		
	}
	else
	{
		$sql="SELECT `kad_pengenalan` FROM `user` WHERE `kad_pengenalan`='$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 = '../registration.php';</script>";
					exit;
		}
		else
		{
			$query="INSERT INTO `user` (`kad_pengenalan`,`nama_user`,`jawatan`,`bahagian`,`katalaluan_user`)
			VALUES ('".$kadPengenalan."','".$nama."','".$jawatan."','".$bahagian."','".$password."')";
			$strQuery = mysqli_query($conn,$query);
			
			if($strQuery) 
				{
					
					echo "<script>alert('Pendaftaran berjaya!');";
						echo "window.location.href = '../index.html';</script>";
						exit;
				}
				else
				{
					mysqli_commit($conn);
					echo "<script>alert('Sila lengkapkan maklumat pendaftaran. ');";
					echo "window.location.href = '../registration.php';</script>";
					exit;
				}
		}
		
		
		
	}
?>

