<?php


$login=mysql_connect('localhost', 'wauhaha_karaoke', 'cross123','wauhaha_karaoke');
	
mysql_selectDB("wauhaha_karaoke",$login);
$SupID = $_POST['SupID'];
$SupName = $_POST['SupName'];
$SupAdd = $_POST['SupAdd'];
$SupCont = $_POST['SupCont'];
$Fax = $_POST['Fax'];
$HP = $_POST['HP'];
$Hot = $_POST['Hot'];
if(($SupName=="")||($SupAdd=="")||($SupCont=="")||($Fax=="")||($HP=="")||($Hot=="")){
	echo "<script>alert('Please fill in your form completely')</script>";
	echo "<script language='javascript'>window.location='addsup.php'</script>";
} 

if($SupName != ""){
	$result = mysql_query("SELECT SupName FROM supplier WHERE SupName = '$SupName'");
if(mysql_num_rows($result) == 1){
		echo "<script>alert('Your name already had registered OR Your SupName had been used! ')</script>";
		echo "<script language='javascript'>window.location='addsup.php'</script>";
}else{
if(strlen($SupCont) < 9){
	echo "<script>alert('Your Contact Number Cannot less than 9 digits ! ')</script>";
	echo "<script language='javascript'>window.location='addsup.php'</script>";

}else{
if(!is_numeric($SupCont)){
				echo "<script language='javascript'>alert('Phone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='addsup.php'</script>";

}else{
if(strlen($HP) < 9){
	echo "<script>alert('Your Contact Number Cannot less than 9 digits ! ')</script>";
	echo "<script language='javascript'>window.location='addsup.php'</script>";

}else{
if(!is_numeric($HP)){
				echo "<script language='javascript'>alert('Phone Number Must Be numeric.')</script>";
		        echo "<script language='javascript'>window.location='addsup.php'</script>";

}else{
if(strlen($Fax) < 9){
	echo "<script>alert('Your Contact Number Cannot less than 9 digits ! ')</script>";
	echo "<script language='javascript'>window.location='addsup.php'</script>";

}else{
if(is_numeric($Fax)){

$query = mysql_query("INSERT INTO ksupplier(SupID,SupName,SupAdd,SupContact,SupFax,SupHp,SupHot)VALUES('$SupID','$SupName','$SupAdd','$SupCont','$Fax','$HP','$Hot')");

		echo "<script language='javascript'>alert(Add Successful.')</script>";
		echo "<script language='javascript'>window.location='ksupplier.php'</script>";	
}else	
		echo "<script language='javascript'>alert(Add Failed.')</script>";
		echo "<script language='javascript'>window.location='ksupplier.php'</script>";
}
}
}
}
}}}
?>