Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

243
Views
Nodejs Mysql null value inserted on database
app.post('', (req, res) => {
    pool.getConnection((err, connection) => {
        if (err) throw err
        console.log('connected as id' + connection.threadID)
        const params = req.body
        var name = params.name
        var tagline = params.tagline
        var description = params.description
        var image = params.image

        connection.query('INSERT INTO beers (name, tagline, description, image) VALUES (name,tagline,description,image)',
            (err, rows) => {
                connection.release()

                if (!err) {
                    res.send('Successfully added record of name' + params.name)
                } else {
                    console.log(err)
                }
            })

        console.log(req.body)
    })
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @derpirscher suggested, you should add the parameter values to the query.

Try to change your code like this:

    const { name, tagline, description, image } = req.body.params; 
    connection.query(
      'INSERT INTO beers (name, tagline, description, image) VALUES (?, ?, ?, ?)',
      [name, tagline, description, image],
      (err, rows) => {
        connection.release();

        if (!err) {
          res.send('Successfully added record of name' + params.name);
        } else {
          console.log(err);
        }
      }
    );
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!