|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-03-03 12:57 UTC] jani@php.net
[2008-03-11 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 30 02:00:01 2025 UTC |
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.