I have a problem with the POST method.
I have a dropdown menu with different tram stops and I have assigned a name to the dropdown menu within my form. On the next page I try to get the selected tram_stop but if I do $POST_['NameOfSelectionBox]
I get nothing. Here's my code:
DROP DOWN MENU:
// list box select command
echo "<select name=$count value=''><option>Please choose desired stop. </option>";
while($r = mysqli_fetch_array($result)) {
echo "1";
echo '<option value='.$r['id'].'>'.$r['name_'].'</option>';
}
echo "</select>"; // Closing of list box
So name = $count
, and $count
is just a variable starting at 1 and going once for each new drop down menu I make, so in my understanding I should be able to get the selected value from the dropdown menu with
$_POST['1']
on my next webpage. This doesn't work and with this code
if(($_POST['1'] == 0))
{
echo "xyz";
}
I found out that is 0 even if something has been selected and submited.
Any suggestions?
Edit: I did the recommended step to fix the problem as I declared all of my variables before using them. No improvements unfortunately.
Furthermore I think he does recognize that the section field with $_POST['1']
, but it's just 0.
EDIT: SOLVED! I had to change it to '<option value='.$r['name_'].'>'.$r['name_'].'</option>';
So I don't get the id back which happend to be 0. Really dumb mistake. Thanks anyway!