I am using this code to try and stop users from completing jobs that have tasks still open in another table. Edit page:Before record updated.
global $conn,$strTableName,$data,$cntcomp;
$sql = "select *, COUNT(JobNo) from subrequests where JobNo='".$_SESSION[$strTableName."_masterkey1"]."' AND CompletedDate IS NULL GROUP BY JobNo";
$rs = db_query($sql,$conn);
$data = db_fetch_array($rs);
$cntcomp = $data["COUNT(JobNo)"];
If ($values["Completed"] && $cntcomp > 0) {
Echo "<font color=red><strong>Open tasks need to be closed before completing jobs.</strong></font>";
return false;
}
If (!$values["InQueue"] && $values["AssignedTo"] == ""){
Echo "<font color=red><strong>Job Requires a Lead to be taken out of Queue.</strong></font>";
return false;
}
The record I am using does have open subrequests and the sql query works fine in phpmyadmin. I think I'm missing something in the php portion of this.
1st question: I have multiple "return false" is that going to work?
2nd: If the user checks the Completed box and hits save it should check subrequests for empty CompletedDates. If it finds empty it should count those and make $cntcomp greater than 0.... Thus giving the error msg.
I don't get any error msg's but it just doesn't work either. Hope someone can help me. Thx!