note 14566 added to function.mysql-insert-id.php

From: Date: Sat, 04 Aug 2001 03:17:14 +0000
Subject: note 14566 added to function.mysql-insert-id.php
Groups: php.notes 
Request: Send a blank email to php-notes+get-16307@lists.php.net to get a copy of this message
If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this: INSERT INTO foo (auto,text) VALUES(NULL,'text'); # generate ID by inserting NULL INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text'); # use ID in second table ...found here: http://www.mysql.com/doc/G/e/Getting_unique_ID.html It works even without inserting the NULL value for some reason ;) The following is great for monitoring: $new_id = mysql_insert_id(); print "New id: $new_id\n"; Hope it helps you all, cheers. http://www.php.net/manual/en/function.mysql-insert-id.php

« previous php.notes (#16307) next »