title: mysqli last insert id
body: <p>I would like to associate the image with firstname, lastname...how can I retrieve the last rowand use it to insert to the other table? I tried <code>$image = $mysqli-&gt;insert_id;</code> then binding but it doesn't work. Can someone help me out?</p>
  
  <pre><code> $image = $mysqli-&gt;insert_id;//this should come from table2
   $stmt = $mysqli-&gt;prepare("
    insert into table1 (username, firstname, lastname, image) 
    select ?,?,?,image from table2 t2 where username = ? and  t2.id = ? 
     ");
   $stmt-&gt;bind_param('sssss', $username, $fname, $lname, $username, $image);
   $stmt-&gt;execute();
  </code></pre>