error { error: bind message supplies 11 parameters, but prepared statement "" requires 12
error { error: bind message supplies 11 parameters, but prepared statement "" requires 12
我创建了 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 (,,,,,,,,,,,)",[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');
})
您在 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])
我创建了 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 (,,,,,,,,,,,)",[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');
})
您在 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])