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 trialBrian Byrkett
1,296 PointsStep Left Out - index.php Contains Error in Header
Because there wasn't a step to add something like the following to index.php:
$section = "home";
It shows both "Shirts" and "Contact" being underlined and the background behind "Shirts" shows white instead of orange.
The video following doesn't show this correction and could leave someone new a bit confused as to why.
Explanation for us Beginners
header.php is looking for a $section variable in each page to determine how to display the underline on the shirts and contact links. This is actually a combination of header.php and the style.css file. Because there is no $section variable in index.php, we are getting a null result rather than true or false.
By adding a $section = "NAME"; variable to index.php, it will compare the section name given to the header.php document and return a false rather than a null because we don't have any special instructions in header.php for index.php; as we do with shirts.php and contact.php.
The end result tells header.php to not display an underline under either of the navigation links.
If I'm missing anything please comment
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Brian,
I recommend that you update the scripts in the navigation to first check if the $section variable is set before doing the equality comparison.
<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>
Setting $section = home;
solves the problem but it's something that you have to remember to do. What if you create another page on your site that doesn't need the $section variable? You still have to remember to set it to something to avoid this problem. By checking if it's set first then you don't have to worry about setting that variable to something on the pages that don't even use it.
What's happening is that the php scripts are generating a notice error and it's being output where the php script is which is inside the class attribute. So each part of the error message is being interpreted by the browser as a class name. A few style rules end up matching and so we get some unintended styles on that page.
Brian Byrkett
1,296 PointsBrian Byrkett
1,296 PointsThank you very much, Jason!
I much prefer this solution over the way I had "fixed" my problem. It would be nice to see something like this amended to the video.
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsYou're welcome. Yes, I think it could be very helpful to new students going through this project if the Teacher's Notes contained a note on how to avoid the error.
mm4
8,600 Pointsmm4
8,600 PointsSweet fix! I must say, it would never occur to me to use something like that - I didn't know isset() even existed. I guess this just comes with lots of practice and debugging...