MYSQL_INSERT_ID() Question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
brookside
Forum Commoner
Posts: 30
Joined: Tue Mar 02, 2004 8:15 pm

MYSQL_INSERT_ID() Question

Post by brookside »

Here is my code:

Code: Select all

<?php
mysql_query($insertProspective);
   $lastID = mysql_query("MYSQL_INSERT_ID()");
   $row = mysql_fetch_array($lastID);
   echo $row;
?>
With mysql_insert_id() I know it is supposed to retreive the auto-increment value inserted. Am I going wrong somewhere in my code?

What I need to do is after inserting a record into the database I need to retrieve the value of the last inserted id and store it in a variable so I can use it in subsequent insert statements.

I hope this makes sense.

Any help would be appreciated.
brookside
Forum Commoner
Posts: 30
Joined: Tue Mar 02, 2004 8:15 pm

Post by brookside »

nevermind i got it working.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

brookside wrote:nevermind i got it working.
Always nice if you post the solution for others who may be looking for help on the same thing.

Mac
Post Reply