ID: 44302
Updated by: [EMAIL PROTECTED]
Reported By: shaneperc at gmail dot com
-Status: Open
+Status: Feedback
Bug Type: MySQLi related
Operating System: Linux 2.6.9
PHP Version: 5.2.5
New Comment:
What does var_dump($id); output in that case? Or
var_dump($db->insert_id); ?
Previous Comments:
------------------------------------------------------------------------
[2008-03-01 07:27:16] shaneperc at gmail dot com
Description:
------------
$mysqli->insert_id is returning nothing. I tried
mysqli_insert_id($mysqli) as well with the same result. You've heard
this before, BUT, I found a reproducible fix. I found that by
concatenating an empty string to the scalar that holds the id, it's then
accessible.
In the code below, if the commented line is uncommented, everything
works as expected. Without adding the empty string, it doesn't work.
(and testing the value doesn't work at all).
I hope this is helpful to someone who can fix this.
Reproduce code:
---------------
$id = (is_numeric($_POST['staff_id'])) ? $_POST['staff_id'] : "new";
if($id == "new"){
if(!$db->query("INSERT INTO staff() VALUES()")){
die("Couldn't insert a new staffer: " . $db->error);
}
$id = $db->insert_id;
if(!$id){
die("<h2>IDs are acting up again! Tell Shane and don't use this
again until further notice</h2>");
}
}
/*$id = $id . ""; -----uncommenting this will make it work-----*/
die($id);
Expected result:
----------------
Expect to see ID number (either one already set, or the newly generated
one). BTW, if $_POST['staff_id'] doesn't require the insert, this works
everytime as expected.
Actual result:
--------------
Nothing on screen, nothing in the generated source.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44302&edit=1