我有这个POST请求
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": "列计数与行 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 );
请问请求有什么问题?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
您必须根据您提供的列值数量提供问号。
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 }); }); });这应该可以工作