I'm working with PHP and MySQL.
Before we start:
I'm aware of SQL-Injection: Please do not suggest alternatives, I already know.
I'm not too hot with SQL queries, I am currently having a PHP loop through an array of field values obtained from a POST
form. These values are then checked against values already in the database, if they are different (and not NULL), the columns will be updated. All of this is done in PHP. I was wondering if there was a way to 'loop' with pure SQL query? Here is the general idea of my code:
foreach($myInfo as $key=>$value){
if($value["mand"]){
$frmErr = $_POST[$value["post"]] == "" ? 1 : $frmErr ;
$frmErrStr .= $_POST[$value["post"]] != "" ? "" : "- Your ".$value["response"]."<br />" ;
}
}
if(!$frmErr){
$updUser = mysql_query("
UPDATE table_name SET
homeTelephone='".$_POST[$myInfo["homeTelephone"]["post"]]."'
WHERE samaccountname='".$samaccountname.
"'");
header("Location: confUpdate.php?s=yes");
}
So to summarize, what I'm looking for here is a pure-MySQL query that will loop through elements within an array, check the posted values ($_POST[$arrayVal]
) against the corresponding database columns and then, if they are different, update the column with the POSTed value.