我尝试做的就是将post中的值插入到我的用户表中。这已经奏效,但现在我在标题中收到了错误。任何帮助将不胜感激。
var express = require('express');
var router = express.Router();
var db = require('../helpers/db');
var empty = require('is-empty');
var Password = require('node-php-password');
router.post('/', function(req, res, next) {
var firstName = req.body.first;
var lastName = req.body.last;
var username = req.body.username;
var password = req.body.password;
var permission = 2;
db.query('SELECT username FROM user WHERE username = ?', [username], function (err, result) {
if (err) throw err;
if (!empty(result)) {
console.log('Taken');
} else {
var hash = Password.hash(password, "PASSWORD_DEFAULT");
var post = {
first: firstName,
last: lastName,
username: username,
password: hash,
permission: permission
};
db.query('INSERT INTO user SET = ?', post, function (err, result) {
if (err) throw err;
console.log('ok');
});
}
res.redirect('/');
});
});
module.exports = router;