Richard Rodriguez Richard Rodriguez - 3 years ago 194
SQL Question

mysqli_insert_id() not working?

I'm getting quite angry over this, I don't know how can this simple situation be so complicated and not work.

Basically:

$lastInsertId = mysqli_insert_id($query);
echo $lastInsertId;


returns NULL

my $query runs fine, inserts perfectly. Anyone knows why I'm not getting the last insert id?

Answer Source

What is $query? You have to pass the mysqli link as parameter ($link = mysqli_connect(...)). Maybe your $query is the result of mysqli_query or something else.

mixed mysqli::mysqli_insert_id ( mysqli $link )

Manual: http://php.net/mysqli_insert_id

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download