PHP - if == not working for 0 or ""
Posted
by
user2933212
on Stack Overflow
See other posts from Stack Overflow
or by user2933212
Published on 2014-05-30T03:05:12Z
Indexed on
2014/05/30
3:26 UTC
Read the original article
Hit count: 64
php
|if-statement
I am checking the validation of the request with an if query,
if ($request_userid == $userid) {
...
}
Thats working as expected. But further testing has shown, that if $request_userid
or $userid
is 0 or "", then the condition is true and the script runs the if query but it shouldn't.
I am currently solving it with:
if ($userid == "" ) {
exit ("exit");
}
But I don't think that this is the right way?
Can you explain why it doesn’t work with the if query and what would be the correct way to check it?
© Stack Overflow or respective owner