Данные профиля «Проблема с MySQL» не отображаются на моей html-странице

Я пытаюсь просмотреть данные из Mysql и передать их на страницу профиля, где я могу видеть информацию о пользователе, но я пробовал много раз и разными способами, но не мог найти способ, а также нет ошибок, которые я использовал {{#each}}{{this.fullname}}{{/each}} Я устал, но данные не отображаются, может ли кто-нибудь помочь мне, пожалуйста, решить эту проблему, или есть другой способ отобразить мои данные

Я использую node js, express и hbs engine

      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});
        }
    });
});

2 ответа

Попробуй это:

      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')
            }
        }
    });
}
});

Как мне получить доступ к данным из profilePage.hbs? Я пробовал много способов, но теперь работаю

Другие вопросы по тегам