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

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

  • 写回答

1条回答 默认 最新

  • 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题