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

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作