0
<select name="country" id="country">
    <option value="IN">India</option>
    <option value="PK">Pakistan</option>
    <option value="UK">United Kingdom</option>
    <option value="US">United State</option>
</select>

When a user selects a country and clicks submit php gets the value="" ie, country code instead of country name.

4
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by Biiim
1
$countries = array('IN'=>'India','PK'=>'Pakistan',
                 'UK'=>'United Kingdom','US'=>'United States');

echo "<form action='actionpage.php' method='post'>\r\n";
echo "<select name='country'>\r\n";
foreach($countries as $k=>$v){
    echo "<option value='{$k}'>{$v}</option>\r\n";
}
echo "</select>\r\n";
echo "</form>\r\n";

actionpage.php

<?php
$countries = array('IN'=>'India','PK'=>'Pakistan',
                 'UK'=>'United Kingdom','US'=>'United States');
echo $countries[$_POST['country']];
?>

if you're going to use it on many pages id put the array in it's own file and include it

Edited by Biiim: added form

Votes + Comments
very well described
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.