You are here: Re: Using LAST_INSERT_ID() « PHP Programming Language « IT news, forums, messages
Re: Using LAST_INSERT_ID()

Posted by Vic Spainhower on 10/02/05 06:07

Thanks Gordon,

The following code seems to work fine ....

$query = "SELECT LAST_INSERT_ID()";
$result = mysql_query($query);
if ($result) {
$nrows = mysql_num_rows($result);
$row = mysql_fetch_row($result);
$lastID = $row[0];
$_SESSION["entryID"] = $lastID;
}


Vic


"Gordon Burditt" <gordonb.f5slx@burditt.org> wrote in message
news:11jti809ho0re4d@corp.supernews.com...
> >I am trying to get the value of the Auto-Incremented key that was
> >assigned
>>using LAST_INSERT_ID(). However, when I execute the following PHP
>>statements
>>after the insert I only get: "value of entryID: Resource id #7" after
>>EVERY
>>insert (it never changes).
>
> The return value of mysql_query is *NOT* the value for last_insert_id().
> Fetch a row (e.g. using mysql_fetch_row) and then look at the column
> you want, and *thats* the value you are looking for.
>
>>..............................
>>$_SESSION["entryID"] = (mysql_query ('SELECT LAST_INSERT_ID() FROM
>>tblShowEntries'));
>>
>>$entryID = $_SESSION["entryID"];
>>echo "value of entryID: $entryID";
>
> Gordon L. Burditt
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация