如何解决“Mysql 问题”配置文件数据未显示在我的 html 页面中
我正在尝试查看来自 MysqL 的数据并将其传递到个人资料页面,在那里我可以看到用户的信息,但我尝试了很多次和不同的方法,但找不到方法,而且我使用的也没有错误{ {#each}}{{this.fullname}}{{/each}} 我也累了,但数据没有显示,有人能帮我解决这个问题,或者是否有另一种方式来显示我的数据
我正在使用 node js、express 和 hbs 引擎
router.get('/profilePage/:userid',function(req,res) {
var userid = req.params.userid;
pool.query('SELECT * from users where id = ?',userid,function(error,results,feilds) {
if (error) {
console.log("error ocurred while getting user details of " + userid,error);
res.send({
"code": 400,"Failed": "error ocurred"
});
} else {
res.render("profilePage",{user:results});
}
});
});
解决方法
试试这个:
router.get('/profilePage/:userid',function(req,res) {
var userid = req.params.userid;
if (!userid) {
//No user id provided
} else {
pool.query('SELECT * from users where id = ?',[userid],(error,results,feilds)=> {
if (error) {
console.log("error ocurred while getting user details of " + userid,error);
res.send({
"code": 400,"failed": "error ocurred"
});
} else {
if (results.length > 0) {
const profile = results[0]
//You can then access the user id with
console.log(profile.id)
res.render("profilePage",{user:profile});
} else {
console.log('unable to retrieve a profile')
}
}
});
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。