I have a bunch of data where I'm allowing people to mass-modify records.
Example:
Contract A - active
Contract B - active
Contract C - not active
The 'active' field is a select box and they can change one or all of them all at once. So then I have a simple update statement:
$val = whatever they selected in the box.Code:UPDATE DTCONTRACT SET active = 1 - active WHERE CONTRACT_ID = 'x' AND active != $val
But my dilemma is this: I have to have an audit trail for what was changed. So how do I check if that specific record actually got updated? I currently have this (and I apologize that it's in PHP but that's what it's written in... but the idea is generally the same):
But the result is always valid so it logs the change... so is there something I can check to see if the update was actually applied??Code:foreach($_POST as $key => $val) { // UPDATE active status of contract if(substr($key, 0, 7) == 'active_') { $query = "UPDATE DTCONTRACT SET active = 1 - active WHERE CONTRACT_ID = '" . substr($key,7) . "' AND active != $val"; $result = $ehandle->update_query($query); if($result) $tbox->log("Updated active status for contract: ".substr($key,7), substr($key,7)); } }
And yes, I know I need to use bind variables but I'm switching to Oracle in a few months and I'll do it once that happens.




Reply With Quote