mysql2 插入值 nodejs

Sal*_*med 4 javascript node.js mysql2 node-mysql2

我有这个帖子请求

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 });

     });
 });
Run Code Online (Sandbox Code Playgroud)

我从中得到这个错误

"error": {
    "code": "ER_WRONG_VALUE_COUNT_ON_ROW",
    "errno": 1136,
    "sqlState": "21S01",
    "sqlMessage": "Column count doesn't match value count at row 1"
}
Run Code Online (Sandbox Code Playgroud)

这是桌子

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
 );
Run Code Online (Sandbox Code Playgroud)

请问这个请求有什么问题吗?

Udi*_*wat 7

您必须根据您提供的列值的数量提供问号。

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 });

     });
 });
Run Code Online (Sandbox Code Playgroud)

这应该有效