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

nav-sprite.png for shirt appears with white background

I've completed the Creating the Headers and Footers section. I embedded the code to underline the Shirts and Contact. The image for Shirts now displays as a white box when you navigate to the home page (index.php). How do I fix this?

2 Answers

Hi Joseph,

You might notice the "shirts" and "contact" link are underlined too.

The reason this is happening on the homepage is because the $section variable is undefined on that page because we didn't need to use it. However, the scripts in the navigation are still running and we're checking if an undefined variable is equal to something. This is causing a php error.

To avoid this we can use the php isset() function to make sure that the variable is set first, before we try to see if it is equal to something.

<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>

If you would like more details about this, like why the background was white or why the links were underlined then I wrote more about this in another post here: https://teamtreehouse.com/forum/creating-the-menu-and-footer-render-error

That worked! Thank you for your help, Jason.