简体   繁体   English

TypeError:无法读取Node JS中未定义的属性“用户名”

[英]TypeError: Cannot read property 'username' of undefined in Node JS

I have an error while trying to post for login in postman.. but an error shown cannot read property username,this is my code 尝试在邮递员中登录进行登录时出现错误。但是显示的错误无法读取属性用户名,这是我的代码

This is the Controllers 这是控制器

var connection = require('../../config/db');

function Todo() {
    this.create = function (req, res, next) {

        var username = req.body.username;
        var password = req.body.password;

        connection.acquire(function (err, con) {
            con.query('SELECT s.id, s.username, s.sls_nama, s.password, g.id as id_group, g.title FROM salesmen s, groups g WHERE g.id = s.group_id AND username = ?', [username], function (error, results, fields) {
                if (error) throw error;
                if (results.length == 0) {
                    // connected!;  
                    if (password == results[0].password) {
                        results[0]['status'] = "Success"
                        res.json(results[0]);
                        res.status(200).send();
                    } else {
                        results[0]['status'] = "Wrong Password"
                        res.json(results[0]);
                        res.status(200).send();
                    }
                } else {
                    res.status(401).json({
                        message: "Wrong password or username"
                    });
                }
            });
        });
    }
}

module.exports = new Todo();    

This is the Routers 这是路由器

var login = require('../controllers/login');

module.exports = {
    configure: function(app) {
        app.route('/login').post(login.create);
    }
};

this is the error shown in postman 这是邮递员中显示的错误

In your where clause, since you have added alias for your table you must have s.username = ? 在where子句中,由于已为表添加了别名,因此必须具有s.username =?。 instead of username = ?. 而不是用户名=?。

SELECT s.id, s.username, s.sls_nama, s.password, g.id as id_group, g.title FROM salesmen s, groups g WHERE g.id = s.group_id AND s.username = ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用节点 JS 向 MongoDB 添加数据,我收到此错误:“TypeError: Cannot read property 'username' of undefined” - Adding data to MongoDB using node JS and I get this error: “TypeError: Cannot read property 'username' of undefined” TypeError:无法读取未定义 React JS 的属性“用户名” - TypeError: Cannot read property 'username' of undefined React JS 类型错误:无法读取未定义的 discord.js 的属性“用户名” - TypeError: Cannot read property 'username' of undefined discord.js TypeError:无法读取未定义 React.js 的属性“用户名” - TypeError: Cannot read property 'username' of undefined React.js Passport.js:无法读取未定义的属性“用户名”(节点) - Passport.js: Cannot read property 'username' of undefined (Node) “ typeError:无法读取未定义的属性“用户名”。” - “typeError: Cannot read property 'username' of undefined.” 类型错误:无法读取未定义的属性“用户名”-- - TypeError: Cannot read property 'username' of undefined-- TypeError:无法读取未定义的属性“用户名”? - TypeError: Cannot read property 'username' of undefined? TypeError:无法读取password.js中未定义的属性“用户名” - TypeError: Cannot read property 'username' of undefined in passportjs 未捕获的类型错误:无法读取未定义的属性“用户名” - Uncaught TypeError: Cannot read property 'username' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM