You are never populating your var username
as it will always will be undefined
and your code will go to else
block(您永远不会填充您的var username
,因为它将始终是undefined
并且您的代码将进入else
块)
app.get('/ViewPage', function (request, response) {
var connection = request.app.get('pool');
if (request.session.loggedin) {
connection.query('SELECT username FROM accounts WHERE username = test', function (error, results, fields) {
if (error) {
console.log(error);
}
else {
if (results[0].username === "test") {
response.redirect('/myCustom');
}
else if (results[0].username === "admin") {
response.redirect('/');
}
else {
response.redirect('/');
}
}
});
} else {
response.redirect('/');
}
});
Update your code and it will work(更新您的代码,它将起作用)
Edit - From what I can see understand from your updated code, the only thing incorrect is how you are using res.render
.(编辑 -从更新的代码中我们可以了解到,唯一不正确的是您如何使用res.render
。) have a look here , it takes a callback function
(在这里看看,它需要一个callback function
)
Try this in your code and let me know if it works(在您的代码中尝试一下,让我知道它是否有效)
response.render('Create_Award.html', { account: results[0], data: results },(err,html)=>{
res.send(html)
});
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…