[thelist] undefined index error - PHP and MySQL

Pringle, Ron RPringle at aurora-il.org
Mon May 7 14:32:06 CDT 2007


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



More information about the thelist mailing list