Jump to content

php says variable has value A, uses value B


karmatiger

Recommended Posts

I use a css sheet that's actually .php so I can make cascading changes easily (style.php) e.g. 

a {color: <?php echo $AccentColor1 ?>;}


 

The colours are set in a separate file with an include command (colours.php). They're typically directly assigned, e.g. 

$AccentColour2 = "#efefef"


 

One colour (and possibly more once I get this to work) is stored in a database and retrieved by $Main_colour. When I echo $Main_colour it shows the expected value, (in this case #a9100c).

 

Here's where the problem arises...

 

If I put 

$AccentColour1 = "#a9100c";


in colours.php, the css in style.php works and everything that is meant to be that colour IS that colour.

 

However, if I put

$AccentColour1 = $Main_colour;


in colours.php, even though the main_colour variable displays the expected value when echoed, the css breaks and everything that is meant to be that colour comes out link blue.

 

It gets even more strange. If I put 

$TempVar = #cdcd57;


$AccentColor1 = $TempVar;


$AccentColor1 = $Main_colour;


the css works but everything that's meant to be #a9100c comes out as #cdcd57 instead... EVEN THOUGH both $AccentColor1 and $Main_colour echo as #a9100c before and after the css is processed.

 

Why is the css refusing to accept $AccentColor1 = $Main_colour?

Have yo uactually verified that the output on the style sheet is what you expect it to be, or are you judging it by a simple refresh and not seeing the chagnes on the screen?  It might be a chache issue.  Second, in the code examples above you go back and forth between $AccentColor1 and $AccentColour1, notice the u difference in the name.  Make sure you have all you vars labeled correctly.

I also manually change it using conventional hex values put into $Accentcolor1 and it works, so unlikely a cache issue.

 

The variable names are uniform in the code; I just had a typo in my post above.

 

Here's another weird thing: If I put:
 

if (isset($Main_colour)) { $AccentColor1 = "#a9100c"; }
 
else $AccentColor1 = "#000000";

echo $AccentColor1;
 
...it prints #a9100c, indicating $MainColour is set, and therefore $Accentcolor1 = #a9100c. Right?

but when it gets to the CSS...

a color: <?php echo $AccentColor1 ?>;}

...with no instance of $accentcolor1 in between so it shouldn't be redefined, it thinks $AccentColor1 = #000000. It still echoes it as #a9100c before and after, but colours the links as #000000. 

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.