Re: Help with mysql_query and INSERT INTO
| From: | Johan Martin | Date: | Sun, 05 Feb 2006 10:37:59 +0000 |
| Subject: | Re: Help with mysql_query and INSERT INTO | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229892@lists.php.net to get a copy of this message | ||
On Saturday, Feb 4, 2006, at 07:22 America/Los_Angeles, Colin Davis wrote:
I need to insert a new record into a MySQL table which has an auto_increment field Ref as the primary index. When I have inserted the new record, I need to get the new Ref value in order to name some files to relate to the record. At the moment I have to do a SELECT command and search for another field (Title) which might not be unique. Is there another way that I get the Ref back after an INSERT? When I use mysql_query with INSERT INTO it only returns true or false, rather than the row. The PHP manual says: Return Values For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. Regards Colin Davishttp://www.php.net/manual/en/function.mysql-insert-id.php This will give you the record id of the last record inserted (or created). Johan Martin Catenare LLC 534 Pacific Ave San Francisco, CA. 94133 Phone: (415) 834-9802 Fax: (415) 294-4495 http://www.catenare.com AOL: catenarellc Yahoo: martin_johan MSN: catenarellc@hotmail.com GTalk: catenarellc@gmail.com FWD: 716798