Many times there is a need to get the autogenerated ID from the last MySQL INSERT performed.

This ID can then be used to perform some more INSERTs particularly in different tables.

As a typical example lets assume you have members table and a seperate table to store their preference for receiving newsletter.
When a new member registers, we perform the first INSERT to add the member details in the member table.
Now our newsletter table needs the memberID generated from this insert so that we can store their preference (In case you are using their memberID as the primary key instead of the username)

They way to perform this is as below

Leave a Reply

Your email address will not be published. Required fields are marked *