|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44302 mysqli_insert_id results
Submitted: 2008-03-01 07:27 UTC Modified: 2008-03-11 01:00 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: shaneperc at gmail dot com Assigned:
Status: No Feedback Package: MySQLi related
PHP Version: 5.2.5 OS: Linux 2.6.9
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: shaneperc at gmail dot com
New email:
PHP Version: OS:


 [2008-03-01 07:27 UTC] shaneperc at gmail dot com
$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;
      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-----*/

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-03 12:57 UTC]
What does var_dump($id); output in that case? Or var_dump($db->insert_id); ?
 [2008-03-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 12:01:29 2024 UTC