Make a Country Dropdown for User Forms in HTML and PHP

New Countries

I work up this morning to hear on Radio 4 News that Kosovo might soon become a new country.

Ethnic purity, making wars and therefore killing people over something as accidental (or in some cases man-made) as a border seems to me to be evil and stupid.

But what does it mean for us right now? It means we’ll have to add another country to our country drop-down lists.

PHP Form with Country Drop-down – Remembering What the User Entered

Here is a zip file containing a PHP example of a form with a country drop down list. If you are creating a form, it is annoying for the user if they make a mistake on the form, and then when they go back to correct the mistake, the form has forgotten all the values they have already typed in. This is easy to fix for text boxes, but less so for drop-down boxes. The zip file has been setup to allow the form to remember the country the user selected.

It uses PHP’s variable variables to do it. This is just an example, you could the countries into a database table to generate the drop-down, but here, I have just supplied the HTML.

Download the HTML / PHP Example

If you prefer to use SQL to build the code for the dropdown list dynamically, this might help : here is the SQL for loading a table with the country codes and country names.

Download the SQL for Country Table


  1. Only in the same way that the Gaza Strip is a region in Israel.

  2. http://Youssef says

    Western Sahara is not (and will never be) a country ! It’s a region in Morocco !

    Thanks πŸ™‚

  3. http://Milinda says

    Thanks very helpful πŸ™‚

  4. http://dm%20lee says


  5. http://Daniel%20Cairol says

    Thank you! Gracias! Helpful! Útil!