2017-07-03 29 views
0
{ Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''mom12345'' at line 1} 

我想在mysql中使用節點js編寫日誌查詢,但由於某種原因,我不斷收到上述錯誤。請任何人協助我。在SQL語法中的錯誤mysql節點js?

var logininfo={ 
username:username, 
password:password 

}; 
con.query('SELECT id FROM userinfo WHERE username=? and password ?',logininfo, function (error, results, fields) { 
      if (error) { 
       console.log("error ocurred",error); 

      } else { 
       console.log('The solution is: ', results); 
       if (results.length > 0) { 
        if ([0].password == password) { 
         console.log("Login Successful"); 

        } 
        else { 
         console.log("Username and password donot match"); 
        } 
       } 
      } 
     }) 

    } 

回答

1

你忘等於號

WHERE username=? and password = ? 
          ---^ 
0

你的第二個參數應的參數的陣列不是對象。

因此改變:

var logininfo={ 
    username:username, 
    password:password 
    }; 

要:

var logininfo=[ 
    username, 
    password 
    ];