【问题标题】:ER_PARSE_ERROR: You have an error in your SQL syntaxER_PARSE_ERROR:您的 SQL 语法有错误
【发布时间】:2018-07-14 11:24:42
【问题描述】:

我正在尝试在 mysql 中选择一行,其中我的变量 req.body.email 位于 Email_Address 列中 这是我的代码 sn-p

app.post('/login', function(req, res){

con.query("select * from people where Email_address= "+ req.body.email, (err, res) => {
    if(err) {
        console.log('the email '+ req.body.email +'does not exist in the database');
        throw err;
    }
    else{
        console.log('selected');
        if(password == req.body.password)
            //res.redirect('index', { title: 'Hey', message: 'Hello there!' });
            res.send('hello');   
    }



});

但我在下面收到错误

错误:ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '@gmail.com' at line 1

关于如何解决它的任何想法

【问题讨论】:

  • 通过添加找到它: var queryy = "select * from people where Email_address=? "; con.query(queryy,[req.body.email], (err, res) => {...}

标签: javascript mysql node.js


【解决方案1】:

你需要在邮件参数中添加',更改

con.query("select * from people where Email_address= "+ req.body.email

con.query("select * from people where Email_address= '"+ req.body.email +"'"

【讨论】:

    猜你喜欢
    • 2019-10-25
    • 2018-08-29
    • 2019-08-29
    • 2023-04-07
    • 2019-05-08
    • 2020-01-18
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多