How to insert data into two table containing the same ID

Hi guys,i dont have any code nor idea how to get this work. Is it possible to insert data from form input into two table with same ID on it? *Something like one table act as primary and the others foreign key

Yes and no. If the ID is an auto-increment field as it should be, you can UPDATE the data. In this case, you simply do something like this…

UPDATE INTO your-table-name SET data-field-1= $data1, data-field-2=$data2 WHERE id=$your-id;

This just updates the data without rewriting the ID field. Hope this helps!

1 Like

Insert into the primary table, capture the last insert id and then include that with the data going to the secondary table.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service