node.js中的MySQL where子句

os8fio9y  于 2023-01-16  发布在  Node.js
关注(0)|答案(1)|浏览(150)

如何使用node.jsMySQL在where子句中传递id?

查看器.jsx

async function redeem(cid) {
  fetch('http://localhost:4000/getDetailsFromCid/${cid}').then(response => {
    return response.json()
  })
    .then(posts => {
      console.log("posts", posts)    

    })
    .then((err) => {
      console.log(err);
    })
}

索引.js

app.get("/api/getDetailsFromCid/:cid", (req, res) => {
    const cid = req.params.cid;
    db.query("SELECT * FROM Details WHERE cid = ?", [cid],
        (err, result) => {
            if (err) {
                console.log(err)
            }
            res.send(result)
        });
});

错误

Viewer.jsx:19          GET http://localhost:4000/getDetailsFromCid/$%7Bcid%7D 404 (Not Found)
6rqinv9w

6rqinv9w1#

您需要使用"not"

fetch(`http://localhost:4000/getDetailsFromCid/${cid}`)

相关问题