//This is my php to view dropdown box <?php
include('connect.php');
//for retriving data from DB and show it in drop down box
$query="SELECT cname FROM country";
$result = mysqli_query ($con, "$query");
echo "<select name=country value=''>";
while($r=mysqli_fetch_row($result))
{
echo "<option value='$r[0]'> $r[0] </option>";
}
echo "</select>";
?>
But when i am storing in DB my country_id is always 0.
You are not fetching country id from SQL Query
Change
$query="SELECT cname FROM country";
To
$query="SELECT cid, cname FROM country"; // Update cid with your country id field
Therefore $r[0]
is getting blank value.
I am going with Pupil's answer to change the query to
$query="SELECT cid, cname FROM country"; // Update cid with your country id field
and then change this
echo "<select name=country value=''>";
to
echo "<select name=country>"; //remove value=''
EDIT:
Please check your column type may be it is "INT" when you try to store text it stores 0.
Use this code for your reference
//This is my php to view dropdown box
<?php
include('connect.php');
//for retriving data from DB and show it in drop down box
$query="SELECT countryid,cname FROM country";
$result = mysqli_query ($con, "$query");
echo "<select name='country'>";
while($r=mysqli_fetch_row($result))
{
echo "<option value='$r[countryid]'> $r[cname] </option>";
}
echo "</select>";
?>