2
代碼應該只有在沒有得分相同的電子郵件比目前的比分更大更新的成績不好字段錯誤,而是顯示錯誤:的Javascript SQL請求在where子句
Error: Error: ER_BAD_FIELD_ERROR: Unknown column 'li' in 'where clause'
function postScores(useremail, username, scoreValue, leaderboardName) {
if (leaderboardName === "GHOSTS" || leaderboardName === "PACMAN" || leaderboardName === "OVERALL") {
connection.query('UPDATE SCORES_' + leaderboardName + ' SET SCORES=' + scoreValue + ' WHERE SCORES < ' + scoreValue + ' AND USER_EMAIL=' + useremail,
function(err, rows, fields) {
if (err) {
console.log("Failed to Update. Attempting to Insert.");
console.log("Error: " + err);
connection.query(
'INSERT INTO SCORES_' + leaderboardName + '(USER_EMAIL, USER_NAME, SCORES) VALUES (?,?,?)', [
useremail, username, scoreValue
],
function(err, rows, fields) {
if (err) {
console.log("Total Failure. Systems down");
} else {
console.log("Success. Inserted new Scores");
}
});
}
});
} else {
// Reference to Non-Existent Leaderboard
return console.log('Specified Leaderboard of the name ' + leaderboardName + ' does not Exist');
}
}
USER_EMAIL應該有引號(就像插入字符串一樣)? – 2014-10-10 10:32:16
使用佔位符會更好,報價。 – TastyLemons 2014-10-10 10:34:34