2 回答

TA貢獻1851條經(jīng)驗 獲得超4個贊
根據(jù)您的環(huán)境,您還應該轉(zhuǎn)義查詢值。如果您使用 mysql,您應該可以使用以下內(nèi)容:
app.post('/visitors/store', (req, res) => {
const name = req.body.name;
const company = req.body.company;
con.query("INSERT INTO visitors(name, company) VALUES(?,?)", [name, company], (results) => {
res.json(results);
});
或不轉(zhuǎn)義:
app.post('/visitors/store', (req, res) => {
const name = req.body.name;
const company = req.body.company;
con.query(`INSERT INTO visitors(name, company) VALUES(${name}, ${company})`, (results) => {
res.json(results);
});

TA貢獻1802條經(jīng)驗 獲得超5個贊
只需停止查詢字符串并在其中包含實際變量:
app.post('/visitors/store', (req, res) => {
const name = req.body.name;
const company = req.body.company;
con.query("INSERT INTO visitors(name, company) VALUES('" + name + "','" + company + "')", (results) => {
res.json(results);
});
});
- 2 回答
- 0 關(guān)注
- 94 瀏覽
添加回答
舉報