exports.adduser = function(db) {
return function(req, res) {
// Get our form values. These rely on the "name" attributes
var userName = req.body.username;
var userEmail = req.body.useremail;
// Set our collection
var collection = db.get('users');
// Submit to the DB
collection.insert({
"username": userName,
"email": userEmail
}, function(err, doc) {
if (err) {
res.send("There was a problem adding the information to the database.");
} else {
// If it worked, set the header so the address bar doesn't still say /adduser
res.location("userlist");
res.redirect("userlist");
}
});
}
}
插入函數如上,我提交表單之後,查看資料庫中是有資料的。但是會印出處if (err)
的錯誤訊息?這是什麼原因造成的,我如果把res.location("userlist");res.redirect("userlist");
移到if err
裡會報錯,不會跳
沒豆豆了 打擾了沒豆豆了 打擾了沒豆豆了 打擾了沒豆豆了 打擾了沒豆豆了 打擾了沒豆豆了 打擾了