I am trying to insert data to 2 tables, customers and profile. In customers is an incremental primary key and profile has this as foreign key.
My hopeless attempt below yields an error:
Cannot add or update a child row: a foreign key constraint fails
$db="registrant";
$link = mysql_connect("localhost","user","pass");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
$result=mysql_query("INSERT INTO customers (uname, password) VALUES ('$username','$password')") or die("Customers Insert Error: ".mysql_error());
$result2=mysql_query("INSERT INTO profile (membertype, firstName, lastName, siteAddress, location, skills, description, paytype, email, phone, mobilePhone, msn, yahoo, aim, vidconf) VALUES ('$memtype','$firstname','$lastname','$url','$location','$skills','$description','$pay','$email','$phone','$mPhone','$msn','$yahoo','$aim','$vidconf')")or die("Profile Insert Error: ".mysql_error());
mysql_close($link);
print "Record added\n";
Whats the proper way of doing this?