0

Here is the query I have to make in the browser:

/line?l1=##&l2=##&l3=##

And here is how I have it implemented with JS:

app.get('/line', (req, res) => {
  let sql = `UPDATE car_info SET
  l1 = ${parseInt(req.query.lineone)},
  l2 = ${parseInt(req.query.linetwo)},
  l3 = ${parseInt(req.query.linethree)}
  WHERE name = '${req.cookies.uName.name}'`;
  let lineQuerys = db.query(sql, (result) => {
    res.send(`l1: ${req.query.lineone}, l2: ${req.query.linetwo}, l3: ${req.query.linethree}`);
    })
});

the l1, l2, and l3 are as they are defined in my MySQL table. I keep getting this output when I type the query in the browser.

l1: undefined, l2: undefined, l3: undefined
1
  • Are you sure that string you sent back is right? Set it to a string and console.log the string to make sure it's correct first. Commented May 20, 2020 at 5:13

1 Answer 1

2

Your url should be /line?lineone=##&linetwo=##&linethree=## because you're getting params by this: req.query.lineone

If you want to keep the short url, the query params should be: req.query.l1

app.get('/line', (req, res) => {
  let sql = `UPDATE car_info SET
  l1 = ${parseInt(req.query.l1)},
  l2 = ${parseInt(req.query.l2)},
  l3 = ${parseInt(req.query.l3)}
  WHERE name = '${req.cookies.uName.name}'`;
  let lineQuerys = db.query(sql, (result) => {
    res.send(`l1: ${req.query.l1}, l2: ${req.query.l2}, l3: ${req.query.l3}`);
  })
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.