title: MySQL- Why is LAST_INSERT_ID() not working for me?
body: <p>I have the following code:</p>
  
  <pre><code>  public function createNewGuide($userID,$guideName)
    {
      $sql =" INSERT INTO myTable(name, updated) 
              VALUES ('$guideName', 'NOW()')";
  
      //Process query
      $this-&gt;query($sql); // This inserts the new row
      $this-&gt;query('LAST_INSERT_ID()'); // This throws an error
  
      return $this-&gt;query_result;
    }
  </code></pre>
  
  <p>My query function looks like this:</p>
  
  <pre><code>  private function query($sql) 
    {
        $this-&gt;query_result = mysql_query($sql, $this-&gt;conn)
          or die("Unable to query local database &lt;b&gt;". mysql_error()."&lt;/b&gt;&lt;br&gt;$sql");   
    } 
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p><strong>MySQL Database Error: You have an error in your SQL syntax; check the
    manual that corresponds to your MySQL
    server version for the right syntax to
    use near 'LAST_INSERT_ID()'</strong></p>
  </blockquote>
  
  <p>I've googled and looked at similar problems, but not found an answer :(</p>
  
  <p>I have not tried the <a href="http://php.net/manual/en/function.mysql-insert-id.php" rel="nofollow noreferrer">PHP function mysql_insert_id()</a>, as I really would like to do this using SQL.</p>