Tuesday 11 April 2017

Insert query is not working! The values are not being reflected on the table

I am trying to register a user in my react-native application. When i press the signup button, the values are not updated in the database. The tables are empty. There doesn't seem to be any error that is being displayed.

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;

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

The query for seems to be working fine. I don't understand the problem. Please help.



via Avikrit Khati

No comments:

Post a Comment