Now, I have another problem about duplication validation of my data in db.. the message "...already exist" if function validate was through. now if I add a new data, same message pop up...and i can't add new data. I try to reverse my return value and I can add but the duplication validation was ignore.
here's my code:in mainController.php
function addDepartment(){
$depart = new department();
$departmentCode = $_POST['departmentCode'];
$departmentDsc = $_POST['departmentDsc'];
$check = $depart->validateDept($departmentCode,$departmentDsc);
if ($check) {
echo "<script language='javascript'>alert('Department Already Exist');
window.location='department.php';</script>";
} else {
$stat = $depart->addDepartment($departmentCode,$departmentDsc);
if($stat){
echo "<script language='javascript'>alert('Department successfully added');
window.location='department.php';</script>";
}else{
echo "<script language='javascript'>alert('Error has occurred while adding the Department');
window.location='department.php';</script>";
}
}
}
and here's the function validateDept codes:
function validateDept($departmentCode,$departmentDsc) {
$con = new connection();
$query = "SELECT departID FROM tbldepart WHERE departCode='".$this->getDepartmentCode()."' ";
$res = mysql_query($query);
if(mysql_num_rows($res)>0){
return false;
} else {
return true;
}
}