.
2021-08-04 12:22
采纳率: 25%
浏览 176
已结题

#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'

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • CSDN专家-sinJack 2021-08-04 12:46
    最佳回答

    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;

    评论
    解决 1 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题