title: Node.js and mysql Callback : query in query callback
body: <p>All I want to do is insert some data if my database doesn't have that, so I put Insert SQL into my callback function of my Select SQL, but I got error like this: </p>
  
  <blockquote>
    <p>{ [Error: Cannot enqueue Query after invoking quit.] code: 'PROTOCOL_ENQUEUE_AFTER_QUIT', fatal: false }</p>
  </blockquote>
  
  <p>my code snippet is here:</p>
  
  <pre><code>db.query('SELECT count(*) as Resultcount FROM tablename WHERE email = ? and password = ?', [post.email, post.password], function(error, result){
      if (result[0].Resultcount == 0){
          var query2 = db.query('INSERT INTO tablename SET ?', [post], function(err, result) {
              if(err){
                console.log(err);
             }
               console.log(result);
            });
      }
      else{
          console.log('have data already');
      }
  });
  </code></pre>
  
  <p>Could someone give me some advice? 
  Thanks </p>
  
  <p>----update----</p>
  
  <p>actually, the callback function of select SQL is not an anonymous function, my code snippet about db.end() is like this:</p>
  
  <pre><code>var QueryResults = new queryResultFuntion(Back_results);
  
      db.query('SELECT count(*) as Resultcount FROM tablename WHERE email = ? and password = ?', [post.email, post.password], QueryResults.queryResult );
  
  
      db.end();
  </code></pre>