重复表单 - 添加到数据库

Ok so the form starts with a drop down which asks the question 'Select how many children you have' and you can select 1-10 and this generates duplicate forms (exact same fields) for the appropriate amount. What I want to know is how can I add each duplicate form to one table.

For example, what I want is: someone has 5 children, each child would get a row in the children table.

At the moment, if 1 child is selected and details are entered, they get entered in the table just fine. So why is it stopping that when its done for more than one, and how can I fix it?

I can update the question to post code if anyone wishes to see it, however the code is just a small part of the whole page (using JavaScript, PHP, HTML and MySQL) and things will get confusing. I'm just looking for ideas and pointers.

Use a counter for the form and add a number to the fieldname

<form>
<?php $counter = 1; ?>
<input type="text" name="child[<?php echo $counter; ?>][name]">
<input type="text" name="child[<?php echo $counter; ?>][age]">
... rest of the form ...
<?php $counter++; ?>
</form>

use $_POST array to retrieve the data in the script that updates the database

make sure the duplicate forms use arrays in the names

so for example:

<select name="numberofchildren">
<option>1</option>
...
</select>

// generated by JS or serverside (don;t know what you do now)
Name of 1st Child: <input type="text" name="children[1][name]"/>
Age of 1st Child: <input type="text" name="children[1][age]"/>
Name of 2st Child: <input type="text" name="children[2][name]"/>
Age of 2st Child: <input type="text" name="children[2][age]"/>
Name of 3st Child: <input type="text" name="children[3][name]"/>
Age of 3st Child: <input type="text" name="children[3][age]"/>

now you can access this with

foreach($_POST['children'] as $child)
{
echo $child['name']; 
echo $child['age'];
}

For the inputs which are being generated you can use "children[]" as name so it will be filled in to an array be sending the form via POST:

`Array(
    [children] => Array(
        [0] => 'test'
        [1] => 'test2'
    )
)`

But show me your code and we'll adjust that.