[英]PHP not allowing insertion into mysql database
錯誤:無法添加或更新子行,外鍵約束失敗( crimereportingsystem
。 suspect
,約束j_fk
外鍵( jail_id
)參考文獻jail
( jail_id
)ON DELETE CASCADE ON UPDATE CASCADE)
$sql="INSERT INTO `suspect` (suspect_id, suspect_name, address, height, eye_colour, weight, plead_type, hair_colour, blood_group, gender, dob, jail_id, release_date, admission_date, lawyer_id, hire_type, Picture, fingerprint)
VALUES
('$suspect_id','$suspect_name','$address','$height','$eye_colour','$weight','$plead_type','$hair_colour', '$blood_group', '$gender', '$dob', '$jail_id', '$release', '$admission', '$lawyer_id', '$hire_type', '$picture', '$fingerprint') ";
為什么PHP會拋出上述錯誤? 我能做什么?
看來您用撇號包裹了太多變量。 嘗試只包裝字符串值的而不是數字的。 我的意思是這樣的:
$sql="INSERT INTO suspect (suspect_id, suspect_name, ...)
VALUES
($suspect_id, '$suspect_name', ...)";
請注意,$ suspect_id 沒有包裝(我想是整數),而$ suspect_name是包裝了(我想是字符串)。
將此想法應用於所有變量。 我希望這會起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.