Hi there:
I want to be able to perform a MySQL table update using values from a dynamically generated form, using the GET method.
As the form is dynamic, the field names and the resultant query are and cannot be hard-coded.
I believe I'd need to use some sort of loop, and have indeed used such a method to perform looped inserts thus:
foreach($HTTP_POST_VARS as $key=>$val) {
$sql2 .= $key . ",";
$sql3 = substr($sql2,0,-1) . ")";
$sql4 = " VALUES ('" . $DBusername . "',";
$sql5 .= "'" . $val . "'" . ",";
$sql6 = substr($sql5,0,-1) . ")";
}//----end foreach
$sql = $sql1 . $sql3 . $sql4 . $sql6;
However updates as you know are slightly different in that the value follows immediately after the fieldname declaration in the SQL query thus:
"UPDATE <table> SET <fieldnames> = '<form_values>' WHERE X=Y";
Can anyone suggest a way of employing, such loop to construct the requred UPDATE query??
Many thanks.
Russ