我有4个表,第一个表有主键,另外3个表有第一个表中的外键。我的问题是,我可以插入其他3个表但我不能插入第一个表。其他3个表的外键empID没有值,它是第一个表的主键。
这是我的插入部分中的代码
//INSERT--------------------------------------------------
//PERSONAL INSERT-------------------------------------------
$sql = "INSERT INTO personal(empID,lastName,firstName,midInit)
VALUES('$empID','$lastName','$firstName','$midInit')";
//EMPLOYMENT INSERT-------------------------------------------
$sql2 = "INSERT INTO emp_econprof(empID,empStat,offDes,workNature,hrsPerweek)
VALUES('$empID','$empStat','$offDes','$workNature','$hrsPerWeek')";
//LIVING INSERT----------------------------------------------
$sql3 = "INSERT INTO living_enviprof(empID,houseNo,street,barangay,
munCity)
VALUES('$empID','$houseNo','$street','$barangay','$munCity')";
//FAMILY INSERT-----------------------------------------------
$sql4 = "INSERT INTO family_prof(empID,spouseLname,spouseFname,spousemidInit,
spouseLiving,ocwSpouse,tot_childNo,diedChild,aliveChild)
VALUES('$empID','$spouseLname','$spouseFname','$spousemidInit',
'$spouseLiving','$ocwSpouse','$tot_childNo',
'$diedChild','$aliveChild')";
$db->exec($sql);
$db->exec($sql2);
$db->exec($sql3);
$db->exec($sql4);
我的代码中缺少什么?