How to pass dropdown selected value to session variable in php mysql

I am getting dropdown value from Mysql. I need to pass dropdown selected value to session value. So that i can use that session value to other form select query.

Thanks in Advance.

$_SESSION['dropdown'] = $row['whatever'];

Need more context if that doesn’t help.

Form1.php

  <?php $queried = mysql_query("SELECT data FROM database");?>
                  <select name="ordername" id="ordername">
                    <option>Select</option>
					<?php while($result = mysql_fetch_array($queried)) { ?>
                    <option value=<?php echo $result['data'];?>><?php echo $result['data'];?></option>
				  <?php }?>
                  </select>

Here is my dropdown code. Based on this dropdown selected value i need to display information of selected order detail in Form2.php. How can i pass and display details.

Using $_POST method i tried. its getting value in Form2.php. But if i did anything there like link click or some operation $_POST value gets cleared and the data destroyed.

How can i do this…Form1.php page is like searching order.

Thanks in advance

In form2.php, you can just add the value of $_POST[‘ordername’] into a session variable as shown above, or if you’re moving on via another submit button from form2 to somewhere else, add the value as a hidden field in the form that contains the submit button in form2.php.

Thanks for Replying

I did this is, its working in Form2.php. But the problem is dropdown selected value display more than one value. i created links( For Multiple values) if i click link… dropdown selected value not retaining. it gets cleared. Giving error. I dont know to retain. In Form1 three dropdown is there. Based on that Form2 display detail…

Reply me.

You need to post your code for form1 and form2, so someone can see what might be wrong. Also don’t say it’s “giving error”, tell us what the error is.

ETA - sorry, that’s sounds more abrupt than I intended.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.