Results 1 to 3 of 3
Mar 2, 2005, 15:02 #1
- Join Date
- Apr 2004
- South Africa
- 0 Post(s)
- 0 Thread(s)
Insert 2 dependant on insert 1's auto_increment value
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?