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

$SupName = $_POST['SupName'];
$SupAdd = $_POST['SupAdd'];
$SupCont = $_POST['SupCont'];

if(($SupName=="")||($SupAdd=="")||($SupCont=="")){
	echo "<script>alert('Please fill in your form completely')</script>";
	echo "<script language='javascript'>window.location='editsup.php?SupID=$SupID'</script>";

}

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

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

}else

$query=mysql_query("UPDATE supplier SET SupName='$SupName', SupAdd='$SupAdd',SupContact='$SupCont' where SupID='$SupID'");

if($query){
	echo "<script language=javascript>alert('Edit successful!!');window.location='http://www.wauhaha.com/karaoke/supplier.php'</script>";
	
}
}
}
}















?>