dshnx48866
dshnx48866
2018-11-22 09:18
浏览 110
已采纳

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

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

图片转代码服务由CSDN问答提供 功能建议

我使用react native来做可以注册,登录,更新和删除的注册表单。 当我想更新学生信息时,我有问题,但它向我提供了所有学生的详细信息。 例如,我作为学生A登录,我只想学生A细节然后点击它,它会发送详细信息到更新界面给用户更新。 但现在问题是,我以学生A的身份登录,我可以看到其他学生的名字让我选择更新他们的详细信息。 如果我只有一个显示谁只是登录的详细信息怎么办?

任何人都可以帮助我吗? 谢谢

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dragon88112
    dragon88112 2018-11-22 09:25
    已采纳

    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

    点赞 评论

相关推荐