I am trying to generate form text fields on the fly and then update all of them at once with new values submitted to a database. I will almost always have more than one field generated. So far with the code I have below I am able to always update the last occurance, but none of the fields that come before get updated. This is probably due to the fact that I have the same name for each generated field and the update query is defaulting to the last one supplied. Does anyone have ideas as to how I can update each field occurance in the database in this way? Maybe from the update query end...
Here is the code:
<form method="get" action="index.php" name="update">
<?
$sqlQuery = "sql query goes here...";
$sqlQueryResults = mysql_query($sqlQuery, $mysql_link);
//loop thru results and display a new pre-filled text field for each result
while ($getRow = mysql_fetch_array ($sqlQueryResults)) {
?>
<? print("<tr>
<td>
//varName is a primary key
<input type=\"hidden\" name=\"varName\" value=\"" .$getRow[varName]."\">
//varName2 is a the text field to be updated
<input type="text" name=\"varName2\" value=\"" . $getRow[varName2] . "\"></td>
print("<tr><td colspan=\"4\"><hr noshade color=\"#BBD400\"></td></tr>");
}
//print one submit button for dynamically generated form fields
print("<tr><td colspan=\"4\"><input type=\"submit\" value=\"edit field name\"></td></tr>");
}
?>
</form>
//action code upon submition of form
if (isset($varName2)){
$updateTextField = "UPDATE database.table SET varName2='$varName2' WHERE varName='$varName'";
mysql_query($updateTextField,$mysql_link);