Forum Moderators: coopster
I am developing what could be likened to a very simple php/mysql forum solution for a client.
I have come to an instance where I need to do two INSERT queries on my MySQL database to put data into two tables. However i need to put the value of one field in the first INSERT into the second as a foreign key sorta thing.
The field i need the value for is an auto incrementing field. Is it possible to return the value of the auto incremented field after and INSERT query so that i can then use this value and insert it into the second table.
I think I could probably do this by doing a SELECT query in between to find the max value of that column and then use that but I can't see this being the most efficient method.
Please can you suggest how to do this.
Many thanks
Richard
Imagine you have user A & B posting. A does the foirst part and immediatley after user B. The scripe for user A then goes to get the latest value in the DB, only to find that it belongs to user B.
That is where mysql_insert_id come in. You can find more info about it at [dev.mysql.com...]