mysqli_insert_id() returns 0 if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value for some reason. PHPBB3-16605