为什么我的Node.js INSERT给了我一个Rethrow非MySQL错误,错误:ER_PARSE_ERROR:你的MySQL语法有错误吗?

时间:2017-10-18 18:16:55

标签: javascript mysql node.js express

我尝试做的就是将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;

0 个答案:

没有答案