title: Why is mysqli_insert_id() always returning 0?
body: <p>I have the following code. The mysqli_insert_id() (in this case &quot;$last_row&quot;), which is supposed to return the last row of the table, is always returning 0. Why is it so?</p>
  <pre><code>&lt;?php
  
  include 'connect-db.php';
  $last_row = mysqli_insert_id($connection);
  
  if ($content != '') {
      $sql = &quot;INSERT INTO myCity VALUES (NULL, 'Stuttgart', 'DEU', 'Stuttgart', 617000)&quot;;
  
      if (!mysqli_query($connection, $sql)) {
          die('Error: ' . mysqli_error($connection));
      }
  
      echo $last_row;
      mysqli_close($connection);
  }
  </code></pre>