2018-11-22 09:18

React native,如何显示数据库中的特定数据以进行更新

  • react-native
  • php

I am using react native to do register form that can sign up, login, update and delete. I have problem with when I want to update student information but it come out all student detail to me. For example, I login as student A, I want to only student A detail and then click it, It will send detail to update interface to give user update. But now the problem is, I login as Student A, I can see other student name for me to choose to update their detail. How to do if I only one to show the detail for who are login only?

Anyone can help me? Thank you

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dragon88112 dragon88112 3年前

    Ok. After your update I advise you to read more about authentication by tokens. In comments to your question you can find mention of JWT token, also you can read about OAuth algorithm or smth else. As far as you use your server only as an API it's the best solution to use tokens for requests authentication. But now for fastest development I advise you to return user id after authorization.

    Change authorization code part with response to this:

    if (isset($check)) {
        echo json_encode($check); 

    Now you will get all user data after authorization as JSON string. Save user ID and pass it to the next request as GET param or header so you'll be able to determine on the server side which user executes this request. You can get user ID from GET param from global $_GET variable like this:

    $loggedInUserId = $_GET['userId'];

    Or from the header:

    $loggedInUserId = $_SERVER['LOGGED_IN_USER_ID'];

    And then you can use this variable inside your query

    $sql = "SELECT * FROM  userregisterinfo WHERE id = " . mysqli_real_escape_string($loggedInUserId);

    So you can get only one row from the table with data of particular user

    点赞 评论 复制链接分享