简体   繁体   English

无法从具有 Node.js 的 MySQL 表中正确检索数据

[英]cannot retrieve data correctly from a MySQL table with Node.js

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:下面是我用 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. l1、l2 和 l3 在我的 MySQL 表中定义。 I keep getting this output when I type the query in the browser.当我在浏览器中键入查询时,我不断收到这个 output。

l1: undefined, l2: undefined, l3: undefined

Your url should be /line?lineone=##&linetwo=##&linethree=## because you're getting params by this: req.query.lineone您的 url 应该是/line?lineone=##&linetwo=##&linethree=##因为您通过以下方式获取参数: req.query.lineone

If you want to keep the short url, the query params should be: req.query.l1如果要保留短 url,查询参数应为: 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}`);
  })
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM