<?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"];
$BYear	   = $_POST["BYear"];
$BMonth	   = $_POST["BMonth"];
$BDay	   = $_POST["BDay"];
$Address1  = $_POST["Address1"];
$Postcode  = $_POST["Postcode"];
$IC        = $_POST["IC"];
$Email     = $_POST["Email"];
$Phone     = $_POST["Phone"];
$HPhone    = $_POST["HPhone"];
$Occupation= $_POST["Occupation"];
$MemID =$_POST["MemID"];


//echo $Username;



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='adminaddmem.php'</script>";
}
if($Username != ""){
	$result = $db->query("SELECT Username FROM regmember WHERE Username = '$Username'");
if($result->num_rows == 1){
		echo "<script>alert('Your name already had registered OR Your username had been used! ')</script>";
		echo "<script language='javascript'>window.location='adminaddmem.php'</script>";die;
}
if(strlen($Password) < 6){
				echo "<script>alert('your password is shorter than 6 words! ')</script>";
				echo "<script language='javascript'>window.location='adminaddmem.php'</script>";
}else {
if(strlen($IC) < 12){
				echo "<script>alert('your IC is shorter than 12 words! ')</script>";
				echo "<script language='javascript'>window.location='adminaddmem.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='adminaddmem.php'</script>";
}else {
if(!is_numeric($Phone)){
				echo "<script language='javascript'>alert('Phone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddmem.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='adminaddmem.php'</script>";
}else {
if(!is_numeric($HPhone)){
				echo "<script language='javascript'>alert('HPhone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddmem.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='adminaddmem.php'</script>";
}else {
if(is_numeric($PostCode)){
				echo "<script language='javascript'>alert('PostCode Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='adminaddmem.php'</script>";

}else{
if($Password !== $Password2){
				echo "<script>alert('your password and confirm password is different! ')</script>";
				echo "<script language='javascript'>window.location='adminaddmem.php'</script>";
}else{
if(is_numeric($IC)){


		
$query = mysql_query("INSERT INTO regmember(Username, Password, Name, Gender, BYear, BMonth, BDay, Address1, Postcode, IC, Email, Phone, HPhone, Occupation,MemID)VALUES('$Username', '$Password', '$Name', '$Gender', '$BYear', '$BMonth', '$BDay', '$Address1', '$Postcode', '$IC', '$Email', '$Phone', '$HPhone', '$Occupation','$MemID')");
	
		echo "<script language='javascript'>alert('Register Successful.')</script>";
		echo "<script language='javascript'>window.location='adminviewmem.php'</script>";
	
	}else
	
		echo "<script language='javascript'>alert('IC Must Be numeric.')</script>";
		echo "<script language='javascript'>window.location='adminaddmem.php'</script>";
		
		}
		}
		}
		}
		}
		}
		}
		}
		}
		}
		
?>