title: LAST_INSERT_ID does not work
body: <p>I have two submit buttons that get values from two forms and insert them in a database. The problem is that I need to get the last inserted id from the first table (courses) to insert into the second table (students) but it does not work. This what I did:</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  $course_name = // the value of the field for the course name
  $student_name = // The first name of the student
  $student_age = // The age of the student
  $last_id = // The last id of table courses
    if(isset($_POST['submit1'])){
            $query1 = "INSERT INTO courses (course_name)VALUES ('$course_name')";
                  if ($object-&gt;query($query1) === true){
                      $last_id = LAST_INSERT_ID();
                      $good = "the course has been created";
                  }
                  else{
                      $bad = "Error: " .$query1.$object-&gt;error;
                  }
      }
  
   if(isset($_POST['submit2'])){
            $query2 = "INSERT INTO students (course_id,student_name, student_age)VALUES ('last_id','$student_name','student_age')";
                  if ($object-&gt;query($query2) === true){
  
                      $good = "the student has been created";
                  }
                  else{
                      $bad = "Error: " .$query2.$object-&gt;error;
                  }
      }
  ?&gt;
  </code></pre>
  
  <p>I do not know why it does not work.</p>