/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] IF OR statement issue

Hello all,

I have a rather simple IF statement with an OR in the code, however I do not think it is working, as when processing the link, it sends me to the wrong location, which doesn’t follow the code.

[code=php]
if($Type === “Oil” or “Market”){
header(‘Location: http://www.test.com/payment.php’);
}
else{
header(‘Location: http://www.test.com/payment2.php’);
}
[/code]

I know the variable

[code=php]$Type[/code]

is being called, because upon checking it by echo’ing it out, it provided what is in the DB, however it didn’t work as I intended. I had

[code=php]$Type = “Both”;[/code]

meaning it should have sent me to payment2.php however it sent me to payment.php.

Does anyone know what could be the issue?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tracknutOct 13.2015 — You've got the same problem as this: http://www.webdeveloper.com/forum/showthread.php?350037-Am-i-doing-the-comparisons-wrong

<i>
</i>if($Type === "Oil" or "Market")


That is a piece of logic created from your usage of English, but not of the php if statement. Break it down:

if($Type === "Oil" ...

That makes sense, right? If the variable $Type contains the string "Oil".... got it, that makes sense.

"or" ...That makes sense.

"Market"

Huh? Just the statement "Market" means nothing. What do you intend by just "Market"? An if statement is trying to compute whether something is true or false, which makes sense with the $Type == "Oil", but how does it calculate true or false from just "Market"?
Copy linkTweet thisAlerts:
@UAL225authorOct 13.2015 — The logic eludes me sometimes! Thanks for the great reply!
Copy linkTweet thisAlerts:
@NogDogOct 14.2015 — And just for general info, because of PHP's loose typing and how it converts string literals to Boolean values, those can be tricky bugs to find. ?
<i>
</i>C:&gt;php -r "var_dump(boolval('market'));"
bool(true)

C:&gt;php -r "var_dump(boolval(''));"
bool(false)

C:&gt;php -r "var_dump(boolval('0'));"
bool(false)

C:&gt;php -r "var_dump(boolval('0.0'));"
bool(true)

:eek:
×

Success!

Help @UAL225 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...