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

Both are underlined when at the homepage. It works ok when on the shirt page and contact page.

<li class="shirts <br />
<b>Notice</b>:  Undefined variable: section in <b>D:\xampp\htdocs\test\inc\header.php</b> on li

that's what shows on my browser when I'm at homepage when using the google chrome's developer tool and inspect the CSS and HTML of the menu link.

Chris Shaw
Chris Shaw
26,676 Points

Hi Bernadette,

This error is saying that you don't have a variable called $section defined in what I assume is a list of items, without being able to see the rest of your code it's hard to say where the problem lies so if you could post that it would help us to help you :smile:.


5 Answers

Hi, thanks for your reply, I fixed mine by adding $section = ""; to the index.php

I had the same problem. What I did is looked at the problem closely. Because we added two $sections and said if the section is equal "==" to shirts or contact the underline will turn on. However, when we go on the index page both are underlined and some glitches might appear.

Therefore, I went to my index.php file and created new section code: $section = "index"; Then I went back to my header.php and edited the class="branding-title to say: if $section is equal "==" to index the underline will be off:

<h1 class="branding-title <?php if ($section == "index") { echo "off"; } ?> "><a href="./">Shirts 4 Mike</a></h1>

Use this method and it should remove the underline from your contact and shirts links when you are on the index page.

Hope this helps, and if you know another way around this that is simpler please tell me. I think because of making another 'if' rule it will limit the flexibility of the whole website.

Gavin Ralston
Gavin Ralston
28,770 Points

In fact, if you just set the $section variable to anything at all, you don't need to go out of your way to do anything else.

The conditional statements will be evaluated, they'll both come up false, and neither the shirts or contact list items would be underlined.

Frank Novello
Frank Novello
19,299 Points

add a $section variable in index.php

Frank Novello
Frank Novello
19,299 Points

I think this happens because the $section variable is undefined when you are on nether page (shirts or contact)

Justinas Pempe
Justinas Pempe
9,523 Points

Was struggling with this for a while. I can not believe Randy skipped it. By the way, in the project files of the following lesson Randy puts $section = "home"; in the index.php.

Thanks for your reply Chris, I figured out how to fix it, By assigning a blank value for $section in index.php it is not underlining both shirts and contact link any more while at the homepage.

$section = "";