Jump to content

PHP not checking if statement for variable


JamesKoash

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!

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.