React native, how to show specific data from database to update












0















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










share|improve this question

























  • First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

    – Abhi Burk
    Nov 22 '18 at 9:25











  • check this question stackoverflow.com/questions/43347645/…

    – Abhi Burk
    Nov 22 '18 at 9:37
















0















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










share|improve this question

























  • First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

    – Abhi Burk
    Nov 22 '18 at 9:25











  • check this question stackoverflow.com/questions/43347645/…

    – Abhi Burk
    Nov 22 '18 at 9:37














0












0








0








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










share|improve this question
















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







php react-native






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 31 at 9:58







ice blue

















asked Nov 22 '18 at 9:18









ice blueice blue

33




33













  • First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

    – Abhi Burk
    Nov 22 '18 at 9:25











  • check this question stackoverflow.com/questions/43347645/…

    – Abhi Burk
    Nov 22 '18 at 9:37



















  • First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

    – Abhi Burk
    Nov 22 '18 at 9:25











  • check this question stackoverflow.com/questions/43347645/…

    – Abhi Burk
    Nov 22 '18 at 9:37

















First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

– Abhi Burk
Nov 22 '18 at 9:25





First a fall you need to store user data somewhere whomsoever is being logged in like in local storage of browser or etc. For secure data auth you can use JWT which help to generate token. JWT: jwt.io/introduction

– Abhi Burk
Nov 22 '18 at 9:25













check this question stackoverflow.com/questions/43347645/…

– Abhi Burk
Nov 22 '18 at 9:37





check this question stackoverflow.com/questions/43347645/…

– Abhi Burk
Nov 22 '18 at 9:37












1 Answer
1






active

oldest

votes


















0














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






share|improve this answer


























  • Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

    – ice blue
    Nov 22 '18 at 9:46











  • You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

    – Nikita Leshchev
    Nov 22 '18 at 9:49











  • I already update my login code inside the question

    – ice blue
    Nov 22 '18 at 10:16













  • okay, all the code write in login.php?

    – ice blue
    Nov 22 '18 at 10:22











  • Nope, only 3 lines with if, other code is for the first part of PHP code

    – Nikita Leshchev
    Nov 22 '18 at 10:27













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427480%2freact-native-how-to-show-specific-data-from-database-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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






share|improve this answer


























  • Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

    – ice blue
    Nov 22 '18 at 9:46











  • You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

    – Nikita Leshchev
    Nov 22 '18 at 9:49











  • I already update my login code inside the question

    – ice blue
    Nov 22 '18 at 10:16













  • okay, all the code write in login.php?

    – ice blue
    Nov 22 '18 at 10:22











  • Nope, only 3 lines with if, other code is for the first part of PHP code

    – Nikita Leshchev
    Nov 22 '18 at 10:27


















0














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






share|improve this answer


























  • Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

    – ice blue
    Nov 22 '18 at 9:46











  • You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

    – Nikita Leshchev
    Nov 22 '18 at 9:49











  • I already update my login code inside the question

    – ice blue
    Nov 22 '18 at 10:16













  • okay, all the code write in login.php?

    – ice blue
    Nov 22 '18 at 10:22











  • Nope, only 3 lines with if, other code is for the first part of PHP code

    – Nikita Leshchev
    Nov 22 '18 at 10:27
















0












0








0







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






share|improve this answer















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







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 10:17

























answered Nov 22 '18 at 9:25









Nikita LeshchevNikita Leshchev

1,143720




1,143720













  • Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

    – ice blue
    Nov 22 '18 at 9:46











  • You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

    – Nikita Leshchev
    Nov 22 '18 at 9:49











  • I already update my login code inside the question

    – ice blue
    Nov 22 '18 at 10:16













  • okay, all the code write in login.php?

    – ice blue
    Nov 22 '18 at 10:22











  • Nope, only 3 lines with if, other code is for the first part of PHP code

    – Nikita Leshchev
    Nov 22 '18 at 10:27





















  • Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

    – ice blue
    Nov 22 '18 at 9:46











  • You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

    – Nikita Leshchev
    Nov 22 '18 at 9:49











  • I already update my login code inside the question

    – ice blue
    Nov 22 '18 at 10:16













  • okay, all the code write in login.php?

    – ice blue
    Nov 22 '18 at 10:22











  • Nope, only 3 lines with if, other code is for the first part of PHP code

    – Nikita Leshchev
    Nov 22 '18 at 10:27



















Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

– ice blue
Nov 22 '18 at 9:46





Thank you for your reply, the .$loggedInUserId need to declare? If need how ?

– ice blue
Nov 22 '18 at 9:46













You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

– Nikita Leshchev
Nov 22 '18 at 9:49





You have to store an id of logged in user into session for example or pass it somehow to script. I need to see how you authorize a user to make my answer more correct. Pls provide more information about authorization.

– Nikita Leshchev
Nov 22 '18 at 9:49













I already update my login code inside the question

– ice blue
Nov 22 '18 at 10:16







I already update my login code inside the question

– ice blue
Nov 22 '18 at 10:16















okay, all the code write in login.php?

– ice blue
Nov 22 '18 at 10:22





okay, all the code write in login.php?

– ice blue
Nov 22 '18 at 10:22













Nope, only 3 lines with if, other code is for the first part of PHP code

– Nikita Leshchev
Nov 22 '18 at 10:27







Nope, only 3 lines with if, other code is for the first part of PHP code

– Nikita Leshchev
Nov 22 '18 at 10:27






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53427480%2freact-native-how-to-show-specific-data-from-database-to-update%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith