我得到「錯誤:沒有參數$ 1」時,我嘗試使用node-postgres客戶端來運行這段代碼:
app.post('/newcause', function (req,res){
console.log(req.body);
var g;
var r = [];
for (g in req.body)
{
r[g]=req.body[g];
console.log('r[g] is ' + r[g]);
}
client = pg.connect(connectionString, function(err, client, done){
if(err) console.log(err);
client.query('INSERT INTO causes (cause_name, goal, organization, sponsor, submitter) VALUES ($1,$2,$3,$4,$5)', r, function(err){
console.log('This is r' + r)
if (err) console.log(err);
});
});
});
有什麼建議?
PS,這是完全錯誤的語句:
{ [error: there is no parameter $1]
name: 'error',
length: 87,
severity: 'ERROR',
code: '42P02',
detail: undefined,
hint: undefined,
position: '81',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
file: 'parse_expr.c',
line: '812',
routine: 'transformParamRef' }
什麼是'r'?你在哪裏傳遞五個查詢參數? – Thilo
我編輯了包含更多關於r的信息。 –
看起來'req.body'不像你期望的那樣。向我們展示您從客戶端使用的POST來調用所有這些。 –