hitman47 Posted June 18, 2013 Share Posted June 18, 2013 The user chooses his year of birth. This is stored in my mysql database. Easy. <select name="year" > for ($year = 1960; $year <= 2030; $year++) { echo '<option value="'.$year.'"><h4>' .$year.'<h4></option>'; } </select> However when i hit submit the form resets to the first option of the list, in this example 1960. If the user chooses 2000 for example and hits submit, the valuse will be passed with post to the next php page, but when i return to this, his choise, 2000, is lost, and it will return to 1960. How can i maintain his option in the select field? Furthermore i want if the user wants to change his option and the select field shows all the options from 1960 to 2030 in a row, not mixed. I am stuck. It is very frustrating. Help!!! Quote Link to comment Share on other sites More sharing options...
Solution doddsey_65 Posted June 18, 2013 Solution Share Posted June 18, 2013 (edited) <select name="year" > for ($year = 1960; $year <= 2030; $year++) { if (!empty($_POST) && $_POST['year'] === $year) { echo '<option selected value="'.$year.'"><h4>' .$year.'<h4></option>'; } else { echo '<option value="'.$year.'"><h4>' .$year.'<h4></option>'; } } </select> You need to check if there is post data and if the posted data matches the value of the option Edited June 18, 2013 by doddsey_65 Quote Link to comment Share on other sites More sharing options...
hitman47 Posted June 18, 2013 Author Share Posted June 18, 2013 (edited) Ok it worked thank you man Edited June 18, 2013 by hitman47 Quote Link to comment Share on other sites More sharing options...
doddsey_65 Posted June 18, 2013 Share Posted June 18, 2013 No problem, remember to mark as answered Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.