#NodeJS项目#Mysql语句出错

数据库语句:
"select * from user where binary "+" username="+username+" and password="+password+" and type="+type;

目的:查询用户名,密码,type来判断用户是否存在and正确

报错:Error: ER_BAD_FIELD_ERROR: Unknown column 'undefined' in 'where clause'

code: 'ER_BAD_FIELD_ERROR',
errno: 1054,
sqlMessage: "Unknown column 'undefined' in 'where clause'",
sqlState: '42S22',
index: 0,
sql: 'select * from user where binary username=undefined and password=undefined and type=NaN'
}
node:internal/process/promises:246
triggerUncaughtException(err, true /* fromPromise */);
^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "登录失败".] {
code: 'ERR_UNHANDLED_REJECTION'

数据库检查了列名对而且没有空格

let sql = "select * from user where binary username="+username+" and password="+password+" and type="+type;
你的sql中where后面为什么要加binary?
改为:let sql = "select * from user where username="+username+" and password="+password+" and type="+type;

SQL异常:
1、变量没有正确传递值,
2、where后面条件拼接有问题

字符串值要用单引号扩起,注意是单引号'不是键盘左上角的那个按键`列名称才是用左上角的按键

let sql = "select * from user where binary username='" + username + "' and password='" + password + "' and type=" + type;


而且看你的代码
select * from user where binary username=undefined and password=undefined and type=NaN'
username和password都是没有值的,检查调用LoginUser的代码,值怎么获取的。type参数也有问题,NaN。

有帮助麻烦点个采纳【本回答右上角】,谢谢~~有其他问题可以继续交流~