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

PHP Build a Simple PHP Application Creating the Menu and Footer Adding Active States to the Navigation

so I did the tutorial correctly but when I go back to the index page the links are both highlighted / underlined

when going to the index page the code has the highlights to all links and a white div background on the shirts link.

2 Answers

Hi Ryan,

This is because the $section variable is undefined on the index page but the nav scripts are still running on that page. php outputs a notice level error informing you about the use of an undefined variable. This error is output where the scripts are which is right inside your class attribute.

This means each part of that message is interpreted as a class name by the browser and it just so happens that some style rules end up matching and you get the unintended styling that you see.

One solution is to just set the $section variable to something on the index page even though you're not going to use it. You have to remember to do this on every page though.

The solution I used was to update the scripts to first check if the variable is set first before using it.

<li class="shirts<?php if ( isset($section) && $section == "shirts") { echo " on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact<?php if ( isset($section) && $section == "contact") { echo " on"; } ?>"><a href="contact.php">Contact</a></li>
Csaba Koles
Csaba Koles
4,644 Points

This has even helped my problem!

Thank you Jason!