<?
require("config.inc");
$OwnerID = $_POST['OID'];
$ownerName = $_POST['OName'];
$Address = $_POST['OAddress'];
$handphone = $_POST['OHP'];
$Sex = $_POST['Osex'];
$Birthday = $_POST['OBir'];
$Email = $_POST['OEmail'];
//echo "<script>alert('".$productType."');</script>";

$query_search = "select * from tbl_owner where owner_ID = '$OwnerID'";
$query_exec = mysql_query($query_search) or die(mysql_error());
$rows = mysql_num_rows($query_exec);
$row = mysql_fetch_array($query_exec);

if($ownerName == ""){echo "<script>alert('Name blank');</script>";}
else if($OwnerID == ""){echo "<script>alert('ID blank');</script>";}
else if($Address == ""){echo "<script>alert('Address blank');</script>";}
else if($handphone == ""){echo "<script>alert('Hand Phone blank');</script>";}
else if($Sex == ""){echo "<script>alert('Sex blank');</script>";}
else if($Birthday == ""){echo "<script>alert('Birthday blank');</script>";}
else if($Email == ""){echo "<script>alert('Email blank');</script>";}
else{
if($row['owner_ID'] == $OwnerID){
echo "<script>alert('Owner ID exist');</script>";
echo "<script>window.location='addOwner.php?ownerID=".$OwnerID."';</script>";
}
else{
$result = mysql_query("insert into tbl_owner (owner_ID,owner_Name,address,handPhone,sex,birthday,email) value ('$OwnerID','$ownerName','$Address','$handphone','$Sex','$Birthday','$Email')");
}

//$row = mysql_fetch_array($result);
}
if($result-->0){
echo "<script>alert('Insert Success');</script>";
echo "<script>window.location='checkOwner.php?ownerID=".$OwnerID."';</script>";
}
else{echo "<script>alert('Failed to Insert');</script>";
echo "<script>window.location='addOwner.php?ownerID=".$OwnerID."';</script>";}
?>