Search code examples
phpmysql-insert-id

Mysqli insert id returning null


$S = "INSERT INTO ". TBD ." (NODE, AV, BV) VALUES ('15', '$name', '$email')";
$Q = $CONN->query($S);
$M = $Q->insert_id;

$M returns NULL not 0


The above script runs the query fine, but will not return the unique ID generated. The table, definitely has a auto increment and is a primary key. I have used the script elsewhere and works fine.

So I have no idea why its returning NULL now.


Solution

  • I think you are calling insert_id wrong. Try this:

    $S = "INSERT INTO ". TBD ." (NODE, AV, BV) VALUES ('15', '$name', '$email')";
    $Q = $CONN->query($S);
    $M = $CONN->insert_id;