I was playing around with this; not sure if this is what you were looking for.
I built a simple form -- array.php --
<form method="post" action="array2.php">
<select name="datarecords[]" multiple>
<option value=field1>Field 1</option>
<option value=field2>Field 2</option>
<option value=field3>Field 3</option>
<option value=field4>Field 4</option>
</select>
<br><br><input type="submit" value="submit">
-- array2.php --
<?
$fieldnames = "(";
$values = "(";
foreach($datarecords as $key => $value) {
if ($fieldnames == "(") {
$fieldnames .= "$key";
} else {
$fieldnames .= ", $key";
}
if ($values == "(") {
$values .= "'$value'";
} else {
$values .= ", '$value'";
}
}
$fieldnames .= ")";
$values .= ")";
$query = "INSERT INTO table_name $fieldnames VALUES $values";
print $query;
?>
When I selected field1, field3, and field3, this printed
INSERT INTO table_name (0, 1, 2) VALUES ('field1', 'field3', 'field4')
The array is always going to return 0, 1, and 2 if you select 3 items, so I don't know how that would help you because if i select field1 field2 and field3, it would always be 0, 1, 2.
But I don't really understand your post. You have a form with multiple pages, and you pass the values along until the final page where there is one submit button?
What I would suggest is using hidden inputs like shown below.
<input type="hidden" name="name" value="<? echo HTTP_POST_VARS['Name']; ?>">
<input type="hidden" name="ID" value="<? echo HTTP_POST_VARS[ID']; ?>">
<input type="hidden" name="TESTDATE" value="<? echo HTTP_POST_VARS['TESTDATE']; ?>">
Then, use a foreach loop that would look something like this
<?
$fieldnames = "(";
$values = "(";
foreach($_POST as $key => $value) {
if ($fieldnames == "(") {
$fieldnames .= "$key";
} else {
$fieldnames .= ", $key";
}
if ($values == "(") {
$values .= "'$value'";
} else {
$values .= ", '$value'";
}
}
$fieldnames .= ")";
$values .= ")";
$query = "INSERT INTO table_name $fieldnames VALUES $values";
print $query;
?>
Note that in the foreach loop, I'm now calling $POST (if your form is set to POST, else use $GET). That should work for you.
Let me know how it goes.
Cgraz