Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 我使用node js的sql查询不会在hbs视图中显示查询结果,我在代码中的其他地方使用了此方法_Node.js_Handlebars.js - Fatal编程技术网

Node.js 我使用node js的sql查询不会在hbs视图中显示查询结果,我在代码中的其他地方使用了此方法

Node.js 我使用node js的sql查询不会在hbs视图中显示查询结果,我在代码中的其他地方使用了此方法,node.js,handlebars.js,Node.js,Handlebars.js,const userName=req.body.userNames; const password=req.body.password con.query("SELECT * FROM users where email = ? AND password = ?", [userName, password], function(err, collections){ if(err){ console.log(err); } else {

const userName=req.body.userNames; const password=req.body.password

con.query("SELECT * FROM users where email = ? AND password = ?", [userName, password], function(err, collections){
    if(err){
        console.log(err);
    }
    else {
        if(collections != 0){
            res.render('userProfile', {collections: collections})
            console.log(collections);
    }
    else{
        res.jason("Incorrect password or Account does not exist, check your login again.. Thank you");
    }
}
});
这是我的手柄栏视图
  • {{{#每个集合} {{collections.fullName}

    {{collections.email}

    {{/每个}}

    引用子变量时,不应将
    集合
    作为把手视图的一部分:

    {{#each collections}}
      {{fullName}}
      {{email}}
    {{/each}}
    
    另外,我认为
    if(collections!=0)
    代码并没有达到您所期望的效果:

    if(collections.length > 0) {
      ...
    }
    

    好的,我现在明白了,因为它是一条记录,所以不需要循环空字段。谢谢,它成功了。如果它解决了您的问题,请标记为已接受。