2015-10-09 63 views
1

無法執行此操作。當我單獨執行查詢時,我沒有收到任何錯誤。'無法讀取未定義'nodeJS的屬性'長度'Mysql

app.post('/Fu',function(req,res,next){ 

    var username = req.body.uname; 
    var pass = req.body.pwd; 

    con.query(' SELECT name FROM fun WHERE name = "' +username+'" ; SELECT password FROM fun WHERE password = "' +pass+'" ',function(err, results,fields) { 



     if (results.length > 0) { 

      var w = results[0].password; 

      var q = results[1].name; 
      //console.log(q); 
      console.log('Login was successful'); 
      } 

     else { 
       console.log('Login was not successful'); 
      } 

    }); 

    res.send("success1"); 

    }); 

有人可以幫我解決這個問題嗎?提前致謝。

+1

你應該添加一個檢查的錯誤。它會給你更多的信息。如果返回錯誤,結果可能是未定義的。 –

回答

0

首先試圖改變自己:

con.query(' SELECT name FROM fun WHERE name = "' +username+'" ; SELECT password FROM fun WHERE password = "' +pass+'" ',function(err, results,fields) { 

到:

con.query(' SELECT name, password FROM fun WHERE name = "' +username+'" AND password = "' +pass+'" ',function(err, results,fields) { 
    if (err) throw err; 
相關問題