[thelist] undefined index error - PHP and MySQL

Jeffrey Barke jeffrey.barke at themechanism.com
Mon May 7 14:51:58 CDT 2007


The problem is that last_insert_id() function is table agnostic.
http://dev.mysql.com/doc/refman/5.0/en/information- 
functions.html#function_last-insert-id

To do it your way, try:
mysql_query("insert statement");

mysql_query("select last_insert_id() as histID");
$result = mysql_query($query, $coacalendar);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$historyID = $row['histID'];
echo "<p>History ID is: $historyID</p>\n";

Jeffrey

--
Cheers.
Jeffrey Barke
jeffery.barke at theMechanism.com
Lead Developer, US
theMechanism - New York City
440 9th Avenue, 8th Floor
New York, NY 10001-1631
t: +1 212.404.3150
c: +1 917.941.1232
f: +1 212.404.3228



http://www.theMechanism.com

Subscribe to theMechcast, our monthly Podcast:
http://feeds.feedburner.com/theMechcast

theMechanism - London
3rd Floor
405 The Strand
London E14 9FW
United Kingdom
t: +44 (0)20 7240 4942
f: +44 (0)20 7240 2262

--
The information contained in this Electronic mail message is attorney  
privileged and confidential information intended only for the use of  
the individual or entity named above. Such information also is  
intended to be privileged, confidential, and exempt from disclosure  
under applicable law. If the reader of this message is not the  
intended recipient or the employee or agent responsible to deliver it  
to the intended recipient, you are hereby notified that any  
dissemination, distribution, or copying of this communication is  
strictly prohibited. If you have received this communication in  
error, please notify us immediately by telephone.

Blah, blah, blah...
--


On May 7, 2007, at 3:32 PM, Pringle, Ron wrote:

> Using PHP 5.1 and MySQL 5.12, I am inserting a record into my  
> database and then attempting to grab the auto-incremented id. The  
> insert works fine but trying to define the last_insert_id as a var  
> is blowing up on me. My code is:
>
> mysql_query("select last_insert_id() as histID from tbl_history");
> $result = mysql_query($query, $coacalendar);
> $row = mysql_fetch_array($result, MYSQL_ASSOC);
> $historyID = $row['histID'];  <---- LINE 60
> echo "<p>History ID is: $historyID</p>\n";
>
>
> The errors are:
>
> Notice: Undefined index: histID in inc_edit_confirm.php on line 60
>
> Out of range value adjusted for column 'histID' at row 1
>
>
> When I run the query manually it aliases the column correctly, but  
> returns a value of 0 instead of the proper value.
>
> I've googled around off and on today but I'm not seeing the  
> probably obvious issues here.
>
> Any help would be greatly appreciated.
>
> Ron
> -- 
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !




More information about the thelist mailing list