简体   繁体   中英

Foreign key not updating with primary key?

These are my 2 tables:

customer_details(c_id,c_name,c_vehicleNumber,c_phone,c_email) primary_key(c_id)AUTO INCREMENT and innoDB.
service_initiation(c_id2,si_id,si_1,si_2,si_3,si_4,si_5) primary_key(si_id) AUTO INCREMENT and innoDB
foreign_key(c_id2) references customer_details(c_id) on delete cascade and on update cascade.

However,i insert values through a html page to the table service_initiation,using PHP code for feilds si_1,si_2,si_3,si_4,si_5 and for c_id2 i use mysql_insert_id/last_insert_id.

Am getting an error saying"error 1452 :cannot add or update a child row: foreign key constaint fails".

Below is my php code:
$value1=mysql_insert_id();
$value2=$_POST['si_1'];
$value3=$_POST['si_2'];
$value4=$_POST['si_3'];
$value5=$_POST['si_4'];
$value6=$_POST['si_5'];



$query="insert into service_initiation(c_id,si_id,si_1,si_2,si_3,si_4,si_5) values ('$value1','','$value2','$value3','$value4','$value5','$value6')";
mysql_query($query);

You have

on delete cascade and on delete update.

but this should be

on delete cascade and on update cascade.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM