"mysql_insert_id() returns 0" Code Answer


According to the manual mysql_insert_id returns:

The ID generated for an AUTO_INCREMENT column by the previous query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.

Since it does not give you false and not the correct number it indicates that the queried table didn't generate an auto-increment value.

There are two possibilities I can think of:

  1. Your table doesn't have an auto_increment field
  2. Since you doesn't provide the link to the mysql_insert_id() but using a link with mysql_query() it might not be the correct table that's queried when retrieving the last inserted id.


  1. Make sure it has an auto_increment field
  2. Provide the link aswell: $waarde = mysql_insert_id($this->db);
By crmanjerovic-6e2fe16755fe on August 20 2022

Answers related to “mysql_insert_id() returns 0”

Only authorized users can answer the search term. Please sign in first, or register a free account.