How do I save the following form?
<form name="myform">
<input type="text" name="title" value="title" />
$result = mysql_query("SELECT id, text from details where parent='$parent'
order by id asc") or die('Error');
while(list($id,$ftext) = mysql_fetch_row($result)) {
?>
<textarea name="formfield<?php echo $id;?>" id="<?php echo $id;?>">
<?php echo $ftext;?>
</textarea>
<?php
}
</form>
As you can see above, the MySQL query will load data and dynamically create textareas:
<textarea name="formfield34" id="34">text</textarea>
<textarea name="formfield56" id="56">more text</textarea>
<textarea name="formfield78" id="78">anothet text</textarea>
I need to update database like this:
$result = mysql_query("UPDATE details SET text='$formfield34' WHERE id ='34'") or die('Error');
$result = mysql_query("UPDATE details SET text='$formfield56' WHERE id ='56'") or die('Error');
$result = mysql_query("UPDATE details SET text='$formfield78' WHERE id ='78'") or die('Error');
The problem is that each form will have a different number of textareas loaded dynamically and different $ids. I can not imagine hot to save this form.
Thanks.
foreachto step through $_POST to find fields calledformfieldxx, and use a little text processing to write the content offormfieldxxto the database whereid=xx.