【发布时间】:2019-01-17 06:27:48
【问题描述】:
因为我是 nodejs 的新手。我不断收到以下错误代码 错误:错误:ER_BAD_FIELD_ERROR:“where 子句”中的未知列“用户”
我正在使用带有 mysql 和 express 的 nodejs。我想编辑用户详细信息,但我收到上述错误。
app.get('/edit', function(req, res, next){
var model = new User(connection);
var user={ id: req.params.id}
model.edit({user}, function(err, rows, fields)
{
// if user not found
if (rows.length <= 0) {
console.log('error', 'User not found with id = ' +
req.params.id)
res.redirect('home')
}
else { // if user found
// render to views/user/edit.ejs template file
res.render('user/edit', {
title: 'Edit User',
//data: rows[0],
id: rows[0].id,
name: rows[0].name,
password: rows[0].password,
email: rows[0].email
})
}
})
});
-----------------------------
Query:
User.prototype.edit = function(id)
{
connection= this.connection;
connection.query('SELECT * FROM users WHERE id = ? ',[id],function(err,
result, fields) {
//if(err) throw err
if(err)
{
console.log("Error : %s ",err );
return false
}
console.log("Result", result);
return result;
})
}
感谢您的帮助...
【问题讨论】: