我创建了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');
})
答案 0 :(得分:1)
您在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])