error {error: сообщение привязки содержит 11 параметров, но подготовленное утверждение "" требует 12 - PullRequest
0 голосов
/ 17 октября 2018

Я создал post api, но не могу понять, почему я получаю эту ошибку?Любое предложение, что мне нужно изменить в моем запросе?Запрос:

   router.post('/bills', function(req, httpres, next) {
    console.log("Inside the bills api");
     const name = req.body.name;const designation = req.body.designation; const department = req.body.department;
    const address = req.body.address;const phone = req.body.phone;const mobile = req.body.mobile;const email = req.body.email;
     const organization = req.body.organization;const city = req.body.city;const state = req.body.state;const pincode = req.body.pincode;const fax = req.body.fax;
 console.log(name,designation,department,address,phone,mobile,email,organization,city,state,pincode,fax)
        pool.query("Insert into bill_to(name,designation,department,address,phone,mobile,email,organization,city,state,pincode,fax) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)",[name,designation.department,address,phone,mobile,email,organization,city,state,pincode,fax])
 .subscribe(
       data => {
           console.log('success',data)
           /*
           if(data.rowCount > 0){
             httpres.json({status : true ,message : ' ok',parameters:req.body });
           }else{
             httpres.send('error');
           }*/

           if(data.rows[0].exists){
             httpres.json({status : true ,message : 'data inserted',parameters:req.body });
           }else{
            httpres.send('error');
           }


   }, err => {
       console.log('error',err)
       httpres.send('error');
   })

1 Ответ

0 голосов
/ 17 октября 2018

Вы поставили точку (.) Вместо запятой (,) между обозначением и отделом в pool.query:

... [name,designation.department,address,phone,mobile,email,organization,city,state,pincode,fax])

Измените его на запятую, и оно должно работать:

... [name,designation,department,address,phone,mobile,email,organization,city,state,pincode,fax])
...