Monday 10 April 2017

Insert query fails to insert data in table

I am using node.js to register user into my react native app. There doesn't seem to be any error as the select query is working fine and i am able to login. But when i try to insert the values are not updated in my table. There doesn't seem to any error in the code.

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

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


router.post('/', 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 'user'('name', 'email', 'password', 'phone') VALUES (?,?,?,?)", function(err,row,fields) {

  });
});
module.exports = router;

This is my react native code

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);
                }



            })

            .done();

      }



via Mohit Bachhav

No comments:

Post a Comment