/* Add User */
router.post('/addUser', function(req, res, next) {
var matrikel_number = req.body.matrikel_number;
// var first_name = req.body.first_name;
var username = req.body.username;
var password = bcrypt.hashSync(req.body.password, 10);
var sql = `INSERT INTO users (matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, role_id, username, password)
SELECT matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, '1', ${username}, ${password}
FROM student_archives
WHERE matrikel_number = ${matrikel_number}`
db.query(sql, function(err, row, fields) {
if (err) {
res.status(500).send({error: 'Something went wrong!'})
}
res.status(200).send('Success');
})
});
SQL运行正常,突然开始出现此引擎错误。我不知道为什么需要帮助。
答案 0 :(得分:0)
如果您的代码中包含这一行,请删除此内容。
app.set('views', path.join(__dirname, 'views'));
为了渲染视图,必须有一些引擎...
像app.set('view engine', 'pug');
你还没有指定。
答案 1 :(得分:0)
/* Add User */
router.post('/addUser', function(req, res, next) {
var matrikel_number = req.body.matrikel_number;
var role_id = 1
var username = req.body.username;
var password = bcrypt.hashSync(req.body.password, 10);
var sql = `INSERT INTO users (matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, role_id, username, password)
SELECT matrikel_number, first_name, last_name, dob, email, address, phone_number, postal_code, '${role_id}', '${username}', '${password}'
FROM student_archives
WHERE matrikel_number = ${matrikel_number}`
db.query(sql, function(err, rows, fields) {
if (!err) {
res.status(200).send('Success');
return false;
}
res.status(500).send({error: 'Something went wrong, please try again!'});
})
});
我进行了上述更改,并且有效。谢谢大家的帮助。