Page 1 of 1

How to make mysql_insert_id work

Posted: Wed Jun 05, 2002 8:43 pm
by MyerInd
I am inserting data into one table where an auto_increment id is formed. I want to place this same id into a second table. I have tried using mysql_insert_id and last_insert_id but always get a "0". The first table is incrementing as it should, but I can't seem to capture this value.

Any thoughts?

I have read and tried suggestions from mysql and php.


Ron

Posted: Thu Jun 06, 2002 3:35 am
by twigletmac
php.net wrote:mysql_insert_id() returns 0 if the previous query does not generate an AUTO_INCREMENT value. If you need to save the value for later, be sure to call mysql_insert_id() immediately after the query that generates the value.
Are you calling the function directly after the query because even a line or two of code inbetween may stop it working.

Mac