PHP, MYSQL workbench, postman not working correctly
PHP, MYSQL workbench, postman not working correctly
I have 2 users in a table, for example Vesna and Silvija, Vesna is first, Silvija second and if I type Silvija in postman he will return me "User does not exist and than Id of a user Silvija. This should be working on a way that Postman return just an Id of a User and if I type user that doesnt exist he should return that user doesnt exist. But when I type a users that doesnt actually exist he will return 2 times that users doesnt exist instead one time because table have 2 users that doesnt match entered user. Hope I have explained it understandably and that someone can help me.
foreach($oUsers as $oUser)
if($oUser->USERNAME == $sUsername)
$_SESSION['user_id'] = $oUser->USER_ID;
$_SESSION['username'] = $oUser->USERNAME;
echo $_SESSION['user_id'];
break;
else
echo ' User does not exist';
1 Answer
1
You can not use echo '...'
inside the foreach loop because echo
is executed in every iteration.
echo '...'
echo
$found = false;
foreach($oUsers as $oUser)
if($oUser->USERNAME == $sUsername)
$_SESSION['user_id'] = $oUser->USER_ID;
$_SESSION['username'] = $oUser->USERNAME;
$found = true;
break;
if($found === true)
echo $_SESSION['user_id'];
else
echo ' User does not exist';
You're welcome.
– 김라댜
Sep 2 at 18:28
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you, it works like a charm :D
– Vanessa
Sep 2 at 18:18