Insert Primary key of Selected Drop down list value as a foreign key in another table using php mysql
<p>I need to insert the selected value primary key to be inserted as a foreign key in another table but neither it gives error and nothing is happening
i have populated the drop down list with the below form</p>

<pre><code>&lt;form id="country" name="form1" method="post" action="datatodb.php"&gt;
&lt;table border="1"&gt;
&lt;tr&gt;
&lt;td&gt;
Select Country :&lt;select name="countryname"&gt;
&lt;?php
include 'dblogin.php';
// Get records from database (table "name_list").
$list=mysql_query("select * from _countries");
// Show records by while loop.
while($row_list=mysql_fetch_assoc($list)){
?&gt;
&lt;option value="&lt;?php echo $row_list['countryid']; ?&gt;"&gt;&lt;?php echo $row_list['countryname']; ?&gt;&lt;/option&gt;
&lt;?php
// End while loop.
}
?&gt;
&lt;/select&gt; &lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;
Add Location :   
&lt;input type="text" name="locationname" value="" maxlength="40"/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td align="center"&gt;
&lt;input type="submit" name="Submit" value="Add" size="20"/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/form&gt;
</code></pre>

<p>With below code im capturing the Values and trying to insert the primary key of 
selected value in another table where it is a foreign key </p>

<pre><code>&lt;?php
include 'dblogin.php';

$countryid=$_POST['countryname']; 
$locationname=$_POST['locationname'];

$countryid = stripslashes($countryid); 
$locationname = stripslashes($locationname);

$countryid = mysql_real_escape_string($countryid);
$locationname = mysql_real_escape_string($locationname);

$sql="insert into _location (locationid, locationname, countryid) values ('NULL','".$locationname."','".$locationname."')";
$result=mysql_query($sql);
?&gt;
</code></pre>

<p>Please help me in getting the selected value primary key and get inserted into another table where it is a foreign key</p>
