Hi,

After a form is submitted, I need to insert data into two tables, the second table needs to use the auto_increment value from the first. How do I acheive this?

I would guess one option would be to use a mySQL function to retrieve a 'last inserted id', but what happens if another record is added to the first table before that id is returned for use with the second?

Another option might be to use a 'known' value (randomly generated value, for example) as the PK, so that I can use the same value when adding a record to the second table (as a foreign key).

Is there a better way of doing this?

TIA.