Jump to content

[SOLVED] Drop Down Default Value After Form Submission


dlebowski

Recommended Posts

What i have is a query that returns a list of values in a database for me to select using a drop down box.  In this case, I have dates in a database and I want each one of those dates to be provided to me as an option in a drop down.  This works perfectly.  What I am having trouble with is when I make a selection from the drop down and click "submit" I want the value that was submitted to be the default value in the drop down.  Currently, the first date shows up by default because I have "ORDER BY Date" in my query.  I want this to actually have the value that I submitted when clicking on "submit" to be the default value in the drop down instead of the earliest date.  So if I have $Date=$_POST['Date'];  with the Date value being "2008-05-09", I want that date to be the default value in the box. 

 

Let me know if this isn't clear and I will elaborate. Thank you in advance.

 

          <?php
                                                include("dbinfo.inc.php");
                                                mysql_connect("localhost",$username,$password);
                                                @mysql_select_db($database) or die( "Unable to select database");
                                                $query = "SELECT * FROM database ORDER BY Date";
                                                $result = mysql_query ($query);
                                                echo "<select name=Date>";
                                                                
                                                while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
                                                echo "<option value=$nt[Date]>$nt[Date]</option>";
                                                }
                                                echo "</select>";
                                                ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.