0

My code is below.

The error I am getting is in a query statement that contains an UPDATE statement.

Why do I get an ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE email = '[email protected]'' at line 1?

controller

...

exports.login = (req, res, next) => {
  const { email, password } = req.body;
  const secretKey = req.app.get('jwt-secret');

  let sql = `SELECT * FROM user WHERE email = ?`;

  User.query(sql, [email], (err, result) => {
    ...
    if (result[0] === undefined || result[0].password !== encrypted) {
      res.status(300).send('ID, PS check plz');
    } else {
      const token = jwtSign(secretKey, result[0].userId, email);

      sql = `UPDATE user SET token = ? WHERE email = ?`;

      User.query(sql, [token, email], (err, result) => {
        console.log(err);
        if (err) {
          return next(err);
        }
        ...
      });
    }
  });
};
5
  • Is token value blank? Commented Aug 11, 2019 at 8:19
  • @Samir There is token in console.log(token) in the nested query but empty in the query results Commented Aug 11, 2019 at 8:25
  • What is a result of console.log(typeof token);? Commented Aug 11, 2019 at 12:01
  • @y15e Token type is String (JWT) Commented Aug 11, 2019 at 12:01
  • There seems to be some issue with the token value. Can you console.log you query as shown here stackoverflow.com/questions/41169797/… Commented Aug 11, 2019 at 14:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.