oceanwap
New Member
- Messages
- 24
- Reaction score
- 0
- Points
- 0
I am creating a user registration form.In this form there is a option to select the country.I am fetching the country name from ip2country database.That also means I can get the country of user by his IP address.
I want the user's country to be automatically selected according to his IP address so it will save his time to select the country manually.Also I am going to use this in mobile site.So typing the C for canada won't work for most of the mobile devices.This is my php code:-
I want this while loop to generate this for appropriate country according to its IP address.
I want to know by which method I can achieve this.
I want the user's country to be automatically selected according to his IP address so it will save his time to select the country manually.Also I am going to use this in mobile site.So typing the C for canada won't work for most of the mobile devices.This is my php code:-
PHP:
<html><head><title>select country</title></head><body>
<?php
mysqli_select_db($connection,"$db");
$sql = "SELECT country_name FROM ip2c GROUP BY country_name";
$result= mysqli_query($connection,$sql);
?>
<form>
<select>
<?php
while($row = mysqli_fetch_array($result))
{
echo "<option>{$row['country_name']}</option>";
}
?>
</select>
</form>
</body>
</html>
<?php
mysqli_close($connection);
?>
HTML:
<option>Afganistaan</option>
<option selected="selected">Canada</option>
<option>Egypt</option>