Forum Moderators: coopster

Message Too Old, No Replies

insert mysql get id from auto increment

insert mysql get id from auto increment

         

drooh

11:16 pm on Mar 9, 2008 (gmt 0)

10+ Year Member



using php to write sql queries

insert into `$table` (`id`, `field1`) values (null, '$field1')

in the table the field id is an integer that is set to auto increment.

my question:
is there a way to get the incremented id value and insert it into another table?

something like this

insert into table, id is incremented by 1 and that value is $x

cameraman

12:29 am on Mar 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mysql_insert_id() [php.net]

coopster

7:06 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Best not to use that function though. More info here:
[webmasterworld.com...]

cameraman

7:11 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yikes, that's awfully stupid - what were they thinking?

coopster

7:23 pm on Mar 10, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The developers likely had the function in place before the nuance was discovered. Rather than pull it out they put a NOTE in the documentation instead. That NOTE has been there for a long time now though. Every time I see that function mentioned in the PHP Forum here I make folks aware that they should consider using the MySQL SELECT statement instead.