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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 
Link to comment
Share on other sites

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.