Jump to content

PHP not checking if statement for variable


Go to solution Solved by taquitosensei,

Recommended Posts

Hi there all,

 

Slowly getting back into PHP after a long hiatus from any coding. Here is a quick piece of code that I put together, to display a logo depending on whether a variable is true or false, but it doesn't seem to be working. 


if ( $showlogo = TRUE ) {
$logo = "<img src=\"logo.png\" \>";
} elseif ( $showlogo = FALSE ) {
$logo = "";
}
echo $logo;

This code is located in is called template.php. Each page on the website, so for example index.php, calls this template using the include function and those pages are where the variable $showlogo are set.

 

Could anyone advise me on why it may not be working?

Thanks!

  • Solution

you need to use == otherwise you're changing the value to TRUE

if($showlog ==True)

 

even better use if($showlogo)  That checks for true/false

Hi there all,

 

Slowly getting back into PHP after a long hiatus from any coding. Here is a quick piece of code that I put together, to display a logo depending on whether a variable is true or false, but it doesn't seem to be working. 

if ( $showlogo = TRUE ) {
$logo = "<img src=\"logo.png\" \>";
} elseif ( $showlogo = FALSE ) {
$logo = "";
}
echo $logo;

This code is located in is called template.php. Each page on the website, so for example index.php, calls this template using the include function and those pages are where the variable $showlogo are set.

 

Could anyone advise me on why it may not be working?

Thanks!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.