我有这个帖子请求
app.post("/msg", (req, res) => {
console.log(req.body)
connection.query('INSERT INTO plans (topic, notes, resources) VALUES
(?)', [req.body.topic, req.body.note, req.body.resource],(error,
results) => {
if (error) return res.json({ error: error });
});
});
我从中得到此错误
"error": {
"code": "ER_WRONG_VALUE_COUNT_ON_ROW",
"errno": 1136,
"sqlState": "21S01",
"sqlMessage": "Column count doesn't match value count at row 1"
}
这是表
CREATE TABLE plans(
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
topic VARCHAR(64) NOT NULL,
notes VARCHAR(200) NOT NULL,
resources VARCHAR(200) NOT NULL
);
请请求怎么了?
您必须根据提供的列值数量提供问号。
app.post("/msg", (req, res) => {
console.log(req.body)
connection.query('INSERT INTO plans (topic, notes, resources) VALUES
(?,?,?)', [req.body.topic, req.body.note, req.body.resource],(error,
results) => {
if (error) return res.json({ error: error });
});
});
这应该有效