/    Sign up×
Community /Pin to ProfileBookmark

The if statement is not working, why??

Hi,

i had been using for so long a snippet like this one

<? if($currentpage=”treatment”) echo “class=act”; ?>

but now im trying it in a page and it doesnt work. The if ignores the condition and echoes anyway regardless of the variable ($currentpage could be anything and it still echoes). I checked the syntax 1 million times and its correct so i really dont understand why is not working. Can you please give me a hint?? The full block of code goes like this

[code=php]
<ul id=”menu”>
<li><a href=”index.html”>Index</a></li>
<li <? if($currentpage=”treatment”) echo “class=act”; ?>><a href=”treatment.php”>Treatment</a></li>[/code]

Thank you.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ShortsApr 28.2010 — Change
[code=php]<? if($currentpage="treatment") echo "class=act"; ?>[/code]

To
[code=php]<?php if($currentpage=="treatment") echo "class=act"; ?>[/code]

First, add the <?php at the beginning so your code can be portable. And be do comparison with ==. A single = just sets $currentpage to have the value "treatment", which will always return true. You can see an example of that by adding an echo $currentpage after your if statement, and then changing "treatment" to another value.
Copy linkTweet thisAlerts:
@supercainauthorApr 28.2010 — Oh man, thank so much. The problem was the missing "=". I cant believe i missed it!! what is really odd is that it was working with only one "=" when ran it locally on my computer but on the web server it didnt so it was driving me nuts.

Thank you!
×

Success!

Help @supercain 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.1,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...