I've racked my brain on this simple test, and have come to the realization that 1) I must be loosing it, or 2) I've found a bug
I have created a very simple form that has one field on it; a multi-select box. Yes, I'm using the correct naming such as Field[] for the multi-select. Whenever I submit the form, every field selected gets printed out twice. I have include 2 very short scripts to look at; one is the simple HTML form, the other is the short php script. Here is the HTML:
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="sqlProcess.php" method="post">
<table>
<tr>
<td>
<select name="TestSelect[]" multiple size="5">
<option value="1">Test 1</option>
<option value="2">Test 2</option>
<option value="3">Test 3</option>
<option value="4">Test 4</option>
</select>
</td>
<tr>
<td>
<input type="submit" value=" Save ">
</td>
</tr>
</table>
</form>
</body>
</html>
and here is the php code that is called when the form above is submitted:
<?php
if (isset($POST['TestSelect']))
{
$TestSelect_item = $POST['TestSelect'];
echo count($TestSelect_item) . " items in array.<br><br>";
foreach ($TestSelect_item as $item)
{
echo $item . "<br>";
}
}
else
{
echo "nothing selected";
}
?>
BUT, here is the output that is generated when the form is submitted:
7 items found in array.
1
2
3
4TestSelect[]=1
2
3
4
WHAT?! I read (somewhere on this site..I think) that Apache 2.0 has a bug, in that the first field in a form always returns the value like "Field=value" rather than just "value". So I even tried putting a single hidden field before the select box, like:
<input type="hidden" name="foo" value="1">
But then the output from the php script looks like this:
8 items found in array.
1
2
3
4foo=1
1
2
3
4
Very weird. Can anyone shed some light on this?
I am running RedHat Linux 2.4.18-19.8.0, with php 4.2.2-8.0.5, and Apache 2.0.40-11. (I'm also running RedHat DB, err, RH Postgres 7.2.3-1, but that's probably not of interest at this point).
Thank you in advance...