how do i redirect from apppost to nodejs?

Your error sounds like you have refined the symbol res so that it isn’t the res from the callback arguments, but rather some other res. It seems that perhaps your actual code is this:'/submit', (req, res) => {
  var sql = "insert into `members` (`email`, `type`, `name`, `uid`) values ('"+ +"', '"+ req.body.type +"', '""', '"+req.body.uid+"')";
    db.query(sql, (err, res) => {
        if (err) throw err;
        if (req.body.type == 'student') {
        } else {

Where the res in this db.query(sql, (err, res) => { overrides the higher scoped res in'/submit', (req, res) => { and you get the wrong res when you try to do res.redirect().

The fix is to make sure you use a different argument name in db.query(sql, (err, qres) => {. Since the code in your actual question shows res1 as that argument, that code should work as you show, but apparently that’s not what is in your actual code.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top