Forum Moderators: coopster
I have got a form that should either insert or update content in a database. The insert part works, as well as the first UPDATE, but the UPDATE in the loop freezes after some 29 loops every time. I've tracked the problem down to the ADOdb function ($db->Execute()). So could anyone please tell me what's wrong
This WORKS:
$query = "UPDATE audit_chestionar
SET idNivel = '".$_POST["nivel"]."',
idProces = '".$_POST["proces"]."',
idSubProces = '".$_POST["subproces"]."',
idClient = '".$_POST["client"]."',
dataAudit = '".$data."',
schimbul = '".$_POST["schimb"]."',
auditori = '".$auditoriId."',
oras = '".$_SESSION["oras"]."',
pers_auditat = '".$_POST["auditat"]."',
respons_zona = '".$_POST["responsabil"]."',
obs = '".$_POST["observ"]."'
WHERE idAudit = '".$_SESSION["record"]["id"]."'";
if ($db->Execute($query) === false) {
print 'error updating: '.$db->ErrorMsg().'<br/>'; }
foreach($_POST["a"] as $key=>$value) {
$query = "UPDATE audit_raspunsuri
SET raspuns = '".$value."',
observatie = '".$_POST["obs"][$key]."'
WHERE idAudit = '".$_SESSION["record"]["id"]."'
AND idIntrebareAudit = '".$key."' ";
if ($db->Execute($query) === false) {
print 'error inserting: '.$db->ErrorMsg().'<br/>'; }
}
pageRedirect($href."&do=list&page=".$page."&id=".$_SESSION['record']['id']);
foreach($_POST["a"] as $key=>$value) {
if (! ($_SESSION["record"]["id"] > 0)) {
die("OOPS! trying to update a non number");
}
[b]if (! preg_match('/^[a-z]+$/i',$key)) {
die("OOPS! invalid key");
}
(Presuming key is a text value, alter to suit)
This might be evident if you remove the quotes from the record field. You don't need to quote a numeric query. However, if the value is blank,
$var=NULL;
select * from some_table where id='$var'
it will not error, it just won't work, records are all numeric and there's no '' (which evaluates to zero anyway.) But this
select * from some_table where id=$var
will give a mysql error, revealing the problem.
....WHERE idAudit = ".$_SESSION["record"]["id"]."
AND idIntrebareAudit = '".$key."'";
Again, not sure what $key is supposed to be, but always check it's what you expect when issuing any query.
key and id are both numeric. I've replaced the preg_match with is_numeric and none of the conditions apply.
I am certain that the problem is not with the variables but with the querying as a number of rows are updated before freezing, and this I cannot understand. I'm actually wondering if there might be something wrong with the table as the other update works.
$_POST["a"] You say the code just freezes? No errors?
I would examine the 'a' values --- there could be issues there. Perhaps some debugging could catch the issue? Have the code spit out something after each loop iteration; it might reveal a specific entry in 'a' that is causing the issue (if it truly is executing and "hanging up" after a certain point).