I have a working php page with an hmtl form where five names can be entered into five different text boxes. Like so:
echo "<form name=\"formname\" action=\"form_review.php\" method=\"post\" enctype=\"multipart/form-data\">
<p>";
for ($i=0;$i<=4;$i++) {
echo "First Name<input type=\"text\" name=\"firstnameT[".$i."]\" value=\"".($firstnameT[$i])."\" maxlength=\"15\"> ";
echo "Last Name<input type=\"text\" name=\"lastnameT[".$i."]\" value=\"".($lastnameT[$i])."\" maxlength=\"15\"><br>";
}
On the page form_review.php:
//Convert POST variables to PHP
if (isset($_POST['firstnameT[]'])) {$firstnameT[]=$_POST['firstnameT[]'];}
else { $firstnameT[] = '';}
if (isset($_POST['lastnameT[]'])) {$lastnameT[]=$_POST['lastnameT[]'];}
else { $lastnameT[] = '';}
//Display the submitted data
for ($i=0;$i<=4;$i++) {
echo "<p> $firstnameT[$i]." ".$lastnameT[$i]."<br>";
}
echo "</p>";
So the problem I'm having is that I want to use <select><option> instead of <input type="text"> so users can select five names from five separate pull-down selectors, and display the selections on the next page, like so:
$query = "SELECT users.user_id, users.first_name, users.last_name, users.city
FROM users";
$result = mysql_query($query) OR DIE("Your query failed: " .mysql_errno() . " " . mysql_error());
echo "<form name=\"formname\" action=\"form_review.php\" method=\"post\" enctype=\"multipart/form-data\">
for ($i=0;$i<=4;$i++) {
echo "<p><select name=\"volunteer[".$i."]\">";
echo "<option value=\"\">Choose a Volunteer</option>";
while($row = mysql_fetch_array($result)) {
$vol_id = $row['user_id'];
$first_name = $row['first_name'];
$last_name = $row['last_name'];
$city = $row['city'];
echo "<option value=\"".$vol_id."\">".$last_name.", ".$first_name." (".$city.")</option>";
} //close WHILE
echo "</select></p>";
mysql_data_seek($result,0); //reset the pointer in the result array for each FOR loop
} //close FOR
The above section of code works fine = the form displays properly, each pulldown has the full list of users, etc. I have even confirmed that the underlying html has unique values for each pulldown choice, and that each pulldown choice has a unique name like:
<select name=volunteer[0]><option value="1">Last, First (city)</option><option value='2'>Last2, First2 (City2)</option></select>
<select name=volunteer[1]><option value="1">Last, First (city)</option><option value='2'>Last2, First2 (City2)</option></select>
But when I submit to review page, I can't get the selected names to display. Here's the pertinent code from "form_review.php":
if (isset($_POST['volunteer[]'])) {$volunteer[]=$_POST['volunteer[]'];}
else { $volunteer[] = '';}
for ($i=0;$i<=4;$i++) {
echo "Volunteer #".$i.": ".$volunteer[$i]."<br>";
}
echo "</p>";
Unfortunately, nothing appears. I'm expecting to get the selected option value following "Volunteer #:", but I'm not. I've counted rows in the array passed to the second page and I consistently get numrows=1, and the value in that resulting array is obviously "".
After five hours of trying a mind-numbing number of variations, I can't wrap my head around the solution. Is there something special/different about passing arrays generated from <select><option> versus arrays generated from <input type=text>???
TIA!
snailguy