Sessions with dropdown menu

I figured out how to use it for an input field nut not dropdown select menu

1st page



<form action="profile.php" method="post" id="basic">

<input type="hidden" name="First_name" value="">
<br>
<input type="hidden" name="Last_name" value="">
<br>
<select name="FavoriteAMDrink">
  <option value="Milk">Milk</option>
  <option value="Coffee">Coffee</option>
  <option value="Tea">Tea</option>
</select>

submit

After they submit, they go to this page where

2nd Page profile.php


<?php
 
//let's start the session /////////
?>
<!-- at top of page -->

<body>

<form action="profile-final.php" method="post" id="basic">

<input type="hidden" name="First_name" value="<?php print $_POST['First_name'];?>">
<input type="hidden" name="Last_name" value="<?php print $_POST['Last_name'];?>">

<select name="FavoriteAMDrink">
  <option>Milk</option>
  <option>Coffee</option>
  <option>Tea</option>
</select>

<select name="FavoriteAMFood">
  <option>Bagel</option>
  <option>Donut</option>
  <option>Fruit</option>
</select>

<select name="Radio">
  <option>Talkshow</option>
  <option>Pop</option>
  <option>Rock</option>
  <option>Soul</option>
</select>
...
</form>

</body>

I am stuck on the select menu part.

Where and how do I form something similar to <?php print $_POST[‘Last_name’];?> in the 2nd page dropdown select area?


would it be the following?

<option value=“Milk”<?=$_SESSION[‘FavoriteAMDrink] == “Milk” ? ’ selected=“selected”’ : ‘’?>>Milk</option>
<option value=“Coffee”<?=$_SESSION[‘FavoriteAMDrink’] == “Coffee” ? ’ selected=“selected”’ : ‘’?>>Coffee</option>
<option value=“Tea”<?=$_SESSION[‘FavoriteAMDrink’] == Tea" ? ’ selected=“selected”’ : ‘’?>>Tea</option>

instead of SESSION u can use $_POST same as First_name and Last_name


<option value="Milk" <?php echo $_POST['FavoriteAMDrink] == "Milk" ? ' selected="selected"' : ''?>>Milk</option>
<option value="Coffee" <?php echo $_POST['FavoriteAMDrink'] == "Coffee" ? ' selected="selected"' : ''?>>Coffee</option>
<option value="Tea" <?php echo $_POST['FavoriteAMDrink'] == Tea" ? ' selected="selected"' : ''?>>Tea</option> 

Thanks but I am getting a blank page on the second page with that code and code error warning right by what you put,

I got it fixed. It was just some syntax errors on the 3rd line =Tea" should be “Tea”… Thanks for getting me on the right track.

Ugghhh!! It does not work at all in wordpress. A regular static website it does work.

They are not in the same directory is one reason.

I can’t use one of those fancy smancy plugins as I need to filter who the info gets sent to based on specific inputs and numbers.

anyone else have a solution?

I am trying to make it so that the same select fields are populated on the second and final page. The 2nd page is in a directory.

So, it is home page with short form, the 3 select fields, then it should redirect to inner page with those same 3 select fields auto populated, and 6 more questions.

I now have it partially on a php driven site.

drop down select on 1st page

then it goes to an inner page


<option value="Milk" <?php echo $_POST['Purpose'] == "Milk" ? 'selected="selected"' : ''?>>Milk</option>
<option value="Bread" <?php echo $_POST['Purpose'] == "Bread" ? 'selected="selected"' : ''?>>Bread</option>
<option value="Coffee" <?php echo $_POST['Purpose'] == "Coffee " ? 'selected="selected"' : ''?>>Coffee</option>

if it helps VA Loan center  has a similar form that does what I want

it does not have to be sessions maybe just echo. I have it working on another site but not where it autopopulates the selected info, it does it for text input fields, but I am stuck on select fields.

What do you see if you just stick


echo '"' . $_POST['FavoriteAMDrink'] . '"';

before the drop-down somewhere to just show that value on screen, what value does it show? Also you know you’ve changed the post varname, is that intentional?