React native, how to show specific data from database to update
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
add a comment |
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
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
add a comment |
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
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
php react-native
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
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 withif
, other code is for the first part of PHP code
– Nikita Leshchev
Nov 22 '18 at 10:27
|
show 10 more comments
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 withif
, other code is for the first part of PHP code
– Nikita Leshchev
Nov 22 '18 at 10:27
|
show 10 more comments
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
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 withif
, other code is for the first part of PHP code
– Nikita Leshchev
Nov 22 '18 at 10:27
|
show 10 more comments
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
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
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 withif
, other code is for the first part of PHP code
– Nikita Leshchev
Nov 22 '18 at 10:27
|
show 10 more comments
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 withif
, 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
|
show 10 more comments
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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