I'm writing a program the INSERTS some data into an sql table(1). The table(1) has an ID that is key and autoincrements. I then want to INSERT some more data into another table(2) that has the same ID as table(1).
I'm not really sure how to do this. I could run a SELECT query but I normally use the ID and at that point I don't know what the ID is. How do I find out what the ID is for a record I've just inserted?
Thanks in advance.
Best way to get ID
Moderator: General Moderators
Re: Best way to get ID
There are built in functions for this.
Code: Select all
mysql_insert_id(); //mysql
$mysqli->insert_id; //mysqli
// or
mysqli_insert_id($Link);