使用Node.JS从MySQL数据库删除用户时遇到问题

时间:2019-05-05 00:00:56

标签: javascript mysql node.js rest ejs

问题:我们在实现删除功能时遇到问题。不确定是否存在有关SQL语法,Node.js语法或两者的问题。我们通过添加CASCADE约束解决了外键约束问题。致力于正确处理文件之间的node.js引用的语法以及删除记录所需的SQL查询。我们没有为delete函数获取任何输入,并且在控制台输出中显示为undefined。如何检查其正确的邮件并相应删除?谢谢!

this.deleteUser = function (user) {
        console.log(user);
        connection.acquire(function (err, con) {
            con.query("DELETE FROM user WHERE mail = ?", user, function (err) {
                con.release();
                if(err) {
                    console.log(err);
                } else {
                    console.log('User deleted successfully');
                }
            });
        });
    };

而不是settings.ejs,而是转到viewusers.ejs

app.post('/viewusers', function(req, res) {
    var user = {
        mail: req.body.mail,
        name: req.body.name,
        password: req.body.password,
        accountLevel: req.body.accountLevel
    };
    databaseFunctions.deleteUser(user);
    res.redirect(req.get('referer'));
});

viewusers.ejs代码段:

<form method="post" action="/viewusers" id="deleteUser">

控制台输出:

{ mail: undefined,
  name: undefined,
  password: undefined,
  accountLevel: undefined }
User deleted successfully

感谢您的帮助!

0 个答案:

没有答案