The data from your form will be accessible in PHP in the $_POST variable (or $_GET, but you should probably use $_POST, eg: <form method="post">
).
The first thing I usually do after designing a form, is to post it back to the script and add this line:
print_r($_POST);
This will show you the structure of the data you're working with. In your case it will look something like this:
array(
"children" => array(
0 => "Bobby",
1 => "Mary",
2 => "Janey"
),
"age" => array(
0 => 8,
1 => 12,
2 => 7
)
);
(I assume there's a corresponding age
field for each children
field, yeah?)
Therefore it's just a matter of looping through the array thusly:
$numKids = count($_POST['children']);
$values = array();
for ($i = 0; i < $numKids; ++$i) {
$values[] = "('" . mysql_real_escape_string($_POST['children'][$i]) . "'"
. ", " . intval($_POST['age'][$i]) . ")";
}
$sql = "INSERT INTO `childTable` (`children`, `age`) "
. "VALUES " . implode(",", $values);