0

I have two tables called location and donor. the location table has a foreign key references to donor. I want to insert the data into these tables using mysql so I wrote these queries but I think there is something wrong because I have no data inserted:

$sql = "INSERT INTO  donor(firstname,middlename,lastname,age,bloodgroup,phone,email,weight,height,pas sword,sex,national_number,permission)
               VALUES  ('$user','$mname','$lname','$age','$bloodgroup','$phone','$email','$weight','$he ight', '$password','$sex', '$national_number','$permission')";


while($vr = mysql_fetch_object($sql))
{$id=mysql_query("SELECT id FROM donor WHERE id=$vr->id")};
$update = mysql_query("INSERT INTO location (id,longitude,latitude) VALUES  ('$id','$long','$lat')");
niha
  • 37
  • 5
  • your `select id` is beyond pointless. you'll just be fetching `$vr->id` if it exists, or an empty record if it doesn't. you already HAVE $vr->id, so there's no point in roundtripping it through the database. And yes, you have errors: `'$he ight'`. note the space. fetch_object expects a query RESULT. you're just passing in a query string. e.g. your code is totally broken. – Marc B Jun 02 '15 at 15:41
  • pls try this link http://stackoverflow.com/questions/30597836/why-i-cannot-assign-foreign-key-to-this-column/30598006#30598006 – Karthik Keyan Jun 02 '15 at 15:41

0 Answers0