<?php
	$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
	mysql_selectDB("wauhaha_karaoke",$login);

$Username  = $_POST["Username"];
$Password  = $_POST["Password"];
$Password2 = $_POST["Password2"];
$Name      = $_POST["Name"];
$Gender    = $_POST["sex"];

$BDay	   = $_POST["sd"];
$Address1  = $_POST["Address1"];
$Postcode  = $_POST["Postcode"];
$IC        = $_POST["IC"];
$Email     = $_POST["Email"];
$Phone     = $_POST["Phone"];
$HPhone    = $_POST["HPhone"];
$StaffID   = $_POST["StaffID"];

if($BDay == "" ){
echo "<script language=javascript>alert('Please Fill In Completely!!');window.location='http://www.wauhaha.com/karaoke/admineditmem.php?MemID=$MemID'</script>";
}	
if(($Username == "")||($Password == "")||($Password == "")||($Name == "")||($Address1 == "")
	||($Postcode == "")||($IC == "")||($Email == "")||($Phone == "")||($HPhone == "")){
				echo "<script>alert('Please fill in your form completely')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}
if($Username != ""){
	$result = mysql_query("SELECT Username FROM staff WHERE Username = '$Username'");
if(mysql_num_rows($result) == 1){
		echo "<script>alert('Your name already had registered OR Your username had been used! ')</script>";
		echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}
if(strlen($Password) < 6){
				echo "<script>alert('your password is shorter than 6 words! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else {
if(strlen($IC) < 12){
				echo "<script>alert('your IC is shorter than 12 words! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else {
if(strlen($Phone) < 9){
				echo "<script>alert('Your Phone Number Cannot lesser than 9 digit ! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else {
if(!is_numeric($Phone)){
				echo "<script language='javascript'>alert('Phone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";

}else{
if(strlen($HPhone) < 9){
				echo "<script>alert('Your Phone Number Cannot lesser than 10 digit ! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else {
if(!is_numeric($HPhone)){
				echo "<script language='javascript'>alert('HPhone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";

}else{
if(strlen($Postcode) < 5){
				echo "<script>alert('Your Phone Number Cannot lesser than 5 digit ! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else {
if(is_numeric($PostCode)){
				echo "<script language='javascript'>alert('PostCode Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";

}else{
if($Password !== $Password2){
				echo "<script>alert('your password and confirm password is different! ')</script>";
				echo "<script language='javascript'>window.location='adminaddstaff.php'</script>";
}else{
if(is_numeric($IC)){
		
$query = mysql_query("INSERT INTO staff(Username, Password, Name, Gender, BDay, Address1, Postcode, IC, Email, Phone, HPhone,StaffID)VALUES('$Username', '$Password', '$Name', '$Gender',  '$BDay', '$Address1', '$Postcode', '$IC', '$Email', '$Phone', '$HPhone','$StaffID')");

		echo "<script language='javascript'>alert('Register Successful.')</script>";
		echo "<script language='javascript'>window.location='adminviewstaff.php'</script>";
	}
		
		}}}}}}}}}}
?>