Apologies if a similar question has been asked in the past - I did search the previous questions but had no luck finding the answer I needed.
I currently have an account option on my website with a 'my settings' area, that allows users to change their details. One of the details they can change is their country. Instead of allowing the user to type the country (in a html textbox), I've made things more restricted by providing a dropdown list of most countries in the world. I've briefed my code below (as I don't want to paste a list of countries and waste time):
<select name="country" id="country" class="required" value="<? echo $row_settings['country']; ?>">
<option value=""></option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
...
<option value="UK">UK</option>
<option value="USA">USA</option>
...
</select>
As this 'my settings' area is for registered users, I obviously have a database table - lets call it 'users' and I'll use a simplified version of it, where I have a 'username' column and a 'country' column. The first row of data (i.e. the first user's details) are 'user1' (the username) and 'UK' (the country). As you'll notice, 'user1' lives in the 'UK' - where this data is the same as one of the dropdown list options (i.e. the <option value="UK">UK</option> shown above).
When on the 'my settings' page, I have selected the option 'UK' from the dropdown list, and clicked the 'Save' button (to UPDATE the data for 'user1' in the table) - however, once the page displays after clicking the 'Save' button, the selected value is, as you'll see above, the first option value in the dropdown list (i.e. <option value=""></option>). But the thing is - the data in the table is updated successfully - so if I were to select the 'USA' option on the list, it would successfully update the 'country' data for 'user1' to 'USA'.
What I'm wanting is, simply for the user to see the country they selected on the list before clicking the 'Save' button - is there a reason why the first option of the dropdown list displays after the form has been submitted and the page reloads and displays? why is this happening? Shouldn't the table data for the 'country' column display (i.e. the 'UK' option, as I selected this in the dropdown list before submitting the form). Yet if I were to use a html textbox for the country part of the form, it would simply display the table data for the 'country' column for the 'user1' row - i.e. it would display 'UK'.
Sorry if any part of this question is confusing or over-described, and many thanks for any replies. If you need, I will provide a link to the page with temporary login details so you can see what I'm talking about.
<select>is nottype="text"does not have avalue=-><select name="country" type="text" ... value="<? echo $row_settings['country']; ?>">. You need to addselectedto the selected option -><select name="country" id="country" class="required">...<option value="UK" selected>UK</option>...</select>. Depending on how you are creating the options, you can do it dynamically ->if($row_settings['country'] == 'UK') echo "selected";