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 Davis


http://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: [EMAIL PROTECTED]
GTalk: [EMAIL PROTECTED]

FWD: 716798

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to