Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Error in 'Adding Active States'

I'm following along with the making a simple PHP application video course.

Following the 'Adding Active States' video, I added $section variables to the index, contact and shirts pages. At this point, the pages still load.

The problem comes when I modify the header PHP file to add the conditional. My html/php code is this:

<li class="shirts <?php if ($section == "shirts") { echo "on" }; ?>"><a href="shirts.php">Shirts</a></li>

Once I add this php snippet, the pages no longer load. Am I doing something wrong? It still appears to be formatted correctly. Am I missing something incredibly simple? Help please!

1 Answer

Drew Butcher
Drew Butcher
33,160 Points

Hey Heather Weaver ,

I am working through those videos too. Here is the code that I added in my header.php file and everything seemed to work fine (meaning the correct underlining occurs).

<li class="shirts <?php if ($section == "shirts") {echo "on";} ?>"><a href="./shirts.php">Shirts</a></li>
<li class="contact <?php if ($section == "contact") {echo "on";} ?> "><a href="./contact.php">Contact</a></li>

I hope this helps.

Best, Drew

It does help! I guess I forgot to put a semi-colon after "on" and so it rendered the whole thing useless. Thanks for your help!

Drew Butcher
Drew Butcher
33,160 Points

Glad I could help. I do that too, apparently JavaScript let's you get away without having the semicolon but php is not so forgiving. Happy TreeHousin' !

best, Drew