插入查询不起作用!这些值没有反映在表格中

时间:2017-04-11 11:12:00

标签: mysql node.js react-native react-native-ios

我正在尝试在我的react-native应用程序中注册用户。当我按下注册按钮时,数据库中的值不会更新。表格是空的。似乎没有显示任何错误。

var express = require('express');
var router = express.Router();
var mysql =  require('mysql');

var connection = mysql.createConnection({
      host: 'localhost',
      user: 'root',
      password: '',
      database:'SampleDb',
})


router.get('/', function(req, res, next) {
  var name = req.body.name;
  var email = req.body.email;
  var password = req.body.password;
  var phone = req.body.phone;

  connection.query("INSERT INTO reg (id,name,email,password,phone) VALUES (null,'?', '?', '?','?')"),[name,email,password,phone];
});
module.exports = router;

这是我的反应原生代码

constructor(props) {
        super(props);
        this.state = {
            name:'',
            email:'',
            password:'',
            phone:'',
            }

        };
     Reg = () => {
            fetch('http://192.168.0.20:3000/UserReg', {
             method : 'POST',
                  headers: {
                  'Accept': 'application/json',
                  'Content-type': 'application/json',
                  },

                  body: JSON.stringify({
                  email:this.state.email,
                  name:this.state.name,
                  password:this.state.password,
                  phone:this.state.phone,

                  })
            })

            .then((response) => response.json())
            .then((res) => {
                  if(res.success=== true){
                  var email = res.message;

                     AsyncStorage.setItem('email', email);
                     Actions.Ideas();}
                     else {
                    alert(res.message);
                }

查询似乎工作正常。我不明白这个问题。请帮忙。

1 个答案:

答案 0 :(得分:0)

之后

connection.query("INSERT INTO reg (id,name,email,password,phone)
VALUES (null,'?', '?', '?','?')"),[name,email,password,phone];

尝试触发提交命令。