【问题标题】:'bind message supplies 1 parameters, but prepared statement "" requires 5' in Node'绑定消息提供 1 个参数,但准备好的语句“”在节点中需要 5'
【发布时间】:2017-05-14 14:31:03
【问题描述】:

我无法弄清楚为什么我的 POST 无法使用 Nodejs 和 Massivejs 工作。我正在尝试使用 Postman 添加测试产品,它给了我 “绑定消息提供 1 个参数,但准备好的语句“”需要 5 个” 错误。我认为这与具有 5 个变量的 SQL 文件有关,但我的邮递员图像显示了 5 个键值对,我认为它们会从 req.body 设置这些变量。

我显然错过了一些东西。有什么想法吗?

server.js

app.post("/api/products", function(req, res, next){
 const newProduct = req.body;
  db.add_product(newProduct, function(err, product){
   if(err){
    console.log(err);
    return res.status(500).send(err)
   }
  return res.status(200).send(newProduct) 
 })
});

add_product.sql

INSERT INTO products (name, description, price, img1, img2)
VALUES ($1, $2, $3, $4, $5);

postman image here

【问题讨论】:

    标签: postgresql post postman massive


    【解决方案1】:

    这对我有用:

    let query: string = `INSERT INTO users(handle, firstname, lastname,
                email, password) VALUES ($1, $2, $3, $4, $5)`;     
    await pool.query(query, [handle, firstname, lastname, email, password]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 2014-11-30
      • 1970-01-01
      • 2013-08-09
      • 2021-12-21
      • 2020-06-24
      • 2021-08-01
      相关资源
      最近更新 更多