title: Return the id of the last MySQL insert in PHP
body: <p>I'm trying to grab the id of the last inserted auto-increment row and cannot successfully grab it.</p>
  
  <pre><code>error_reporting(E_ALL);
  ini_set('display_errors', 1);
  mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
  
  $title = mysqli_real_escape_string($conxn,$_POST['blog_title']);
  $entry = mysqli_real_escape_string($conxn,$_POST['blog_entry']);
  $sourceName = mysqli_real_escape_string($conxn,$_POST['blog_source_name']);
  $sourceLink = mysqli_real_escape_string($conxn,$_POST['blog_source_link']);
  
  if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  
  $sql="INSERT INTO blog (blog_title, blog_entry, blog_source, blog_link)
  VALUES ('$title','$entry','$sourceName','$sourceLink')";
  
  $lastID = $mysqli-&gt;insert_id;
  
  if (!mysqli_query($conxn,$sql)) {
  die('Error: ' . mysqli_error($conxn));
  }
  </code></pre>
  
  <p>When I echo <code>$lastID</code> a "0" is returned after every submit.</p>