Homeowner Loans - Car Insurance - Remortgages - Flights - Mortgage

PDA

View Full Version : Get SQL ID


Weirfire
Oct 10th 2005, 1:58 pm
I have a table where I'm auto incrementing as data is inserted. I was wondering how I would obtain that ID to add data into another table at the same time where I want to use that ID?

T0PS3O
Oct 10th 2005, 2:14 pm
INSERT INTO Table 1 id = '' //auto increment

$last_insert_id = mysql_insert_id();

INSERT INTO Table 2 id = $last_insert_id

Weirfire
Oct 10th 2005, 2:19 pm
Thanks Johan. :)

You're not just a pretty face after all :p

T0PS3O
Oct 10th 2005, 2:21 pm
:D Thanks Braveheart.

Have you heard of this thing called Google (http://www.google.co.uk/search?hl=en&q=mysql+last+insert+id&btnG=Search&meta=)? ;)

Weirfire
Oct 10th 2005, 2:23 pm
I like helping out DP though. I figure that if I go to DP first then not only will I get my answer straight away but I set up all the keywords for newbies like myself trying to figure these problems out.