mysql2 插入值 nodejs
mysql2 inserting values nodejs
我有这个 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": "Column count doesn't match value count at row 1"
}
这是table
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 });
});
});
这应该有效
我有这个 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": "Column count doesn't match value count at row 1"
}
这是table
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 });
});
});
这应该有效