我试图显示我在mysql数据库中插入的数据。但是没有显示该值

时间:2017-04-19 04:21:11

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

我想显示我存储在数据库中的用户名。我无法检索任何值。似乎没有任何错误。我想我无法正确访问数据库,但我无法弄清楚我哪里出错了。

这是我的反应原生代码。

export default class UserProfile extends Component{

constructor(props) 
              {
              super(props);
              this.state={
                          name:'',
                          email:'',
                          }
               };
componentWillMount() {
          return this.getUser()
        }

getUser(){
        return fetch('http://192.168.0.20:3000/userprofile',{
        method:'POST',
        headers:{
              'Accept':'application/json',
              'Content-Type':'application/json',
              }
        body: JSON.stringify({
                  name: this.state.name,
                })
        })
       .then((response) => response.json())
       .then((responseData) => {})
        }
render(){
      console.disableYellowBox = true; //// to disable warning :)
      return(
            <Text> Username:{this.state.name}</Text> // trying to display name here.
          );
        }
      }  

这是我的后端代码。

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

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

/* our backend endpoint to check for users ian the database */
router.post('/', function(req, res, next) {

        var name=req.body.name;
        var phone=req.body.phone;
        var email = req.body.email;
        var password = req.body.password;

        connection.query("SELECT * FROM user WHERE email = ? ",[email],function(err,row,fields){
          console.log(name);
          if (err) console.log(err);
  });
  });

module.exports = router;

0 个答案:

没有答案