I'm trying to insert into two tables (parent and child) at the same time from php. This is how I programmed it; I'll insert a unique number together with my original data into the parent table then use the same unique number to fetch the last data I inserted just to get the "id" of the recent data, so I can use it in the child table. It inserts successfully into the first table but did not insert into the second table. I'm getting this error:
Cannot add or update a child row: a foreign key constraint fails (
attendance_db.attendance_tb, CONSTRAINTattendance_tb_ibfk_1FOREIGN KEY (student_id) REFERENCESstudent_tb(id) ON DELETE CASCADE ON UPDATE CASCADE).
How do I insert into the two tables successfully? Any other method will be accepted. Thanks.
NOTE: I created the relation from the designer menu in phpmyadmin.
 
     
    