I am Trying to insert record in 2 tables which are in primary and foreign key relationship. but i were facing a problem "duplicate primary key" error eventhough the table being totally empty.i need to insert clgId in both the table it will be foreign key for the course table .so here i have solved the problem with using help of expert Mr Mika
here is my complete solution
Quote:
// **** Inserting data into clgmaster table ****
$query="insert into clgmaster (ClgId,ClgName,ClgAddrs,FeeAmt,CntNo,Email,Pwd) values ($id,'$clgnm','$addrs',$fees,$cntno,'$eml','$pwd')";
$result = mysql_query($query);//Excecuting clg query
echo $result."
";
if ($result)
{
echo "
You Have Successfully REGISTERED this Record!";
}
else
die("
mysql error ".mysql_error()); //Checking for Error
echo "
";
// **** inserting data into course table ****
$query1="insert into course (ClgId,CourseName) values ($id,'$course')";
echo $query1;
$result1 = mysql_query($query1);//Executing course query
if(!$result1)
{
die("
Mysql erro".mysql_error());
}
else
echo "
record inserted successfully in course";
}