skip to Main Content

I am not able to execute post request in postman.
It gives a internal server error. Here I am using localhost with phpmyadmin.

Here is my code for POST data using postman.

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

  const username = req.body.username
  const password = req.body.password
  const sql = "INSERT INTO `dataa`(`username`, `password`) VALUES (?, ?)"

  db.query(sql, [username, password], (err, rows, fields) => {
    if(!err)
    res.send(rows);
    else {
      console.log(err);
    }
  })
})

2

Answers


  1. Table name shouldn’t be in quotation
    Use like this

    const sql = “INSERT INTO dataa(‘username’,’password’) VALUES (?, ?)”

    Login or Signup to reply.
  2.      app.post('/login', (req, res) => {
           const username = req.body.username
           const password = req.body.password
           let payload={}
           payload.username=username
           payload.password=password
            var query = db.query('INSERT INTO dataa SET ?', payload, function (error, results, fields) {
              if (error) throw error;
              // Neat!
            });
            })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search