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

Aaron Garcia
Aaron Garcia
2,245 Points

Solution: notice undefined variable section title in include()

I am working in a development environment in netbeans/xampp. This error was popping up and creating a layout error on only the index page. If there is a white space over your shirts link, you will need to include the following in your index.php

$pageTitle = "Tshirts designed by a frog";

$section = "index"

include 'inc/header.php';

add to your header.php

line 14 should look like this (I had to kill the <> on each end for the post)

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

3 Answers

Without a semicolon after $section = "index" there's definitely going to be some errors, not sure if that is reflected in your actual code or not. The current stage of the project isn't applying a conditional to the h1 tag since the conditional is to show active links, which the css won't apply to the h1, only to the unordered list. So currently, you don't need the conditional inside the class attribute on the h1. You're current conditional really isn't doing anything.

Aaron Garcia
Aaron Garcia
2,245 Points

The semicolon would not create this specific error and is in the original code but good catch all the same. Follow the link for the explanation I found why you need to have the conditional.on a development server... the code works fine on a production server but I couldn't move forward until I figured out why I was getting an error.

http://stackoverflow.com/questions/14503650/undefined-variables.

Having looked at the link you provided, no one said the lack of a semicolon would create a "SCREAM" error.

I'm inclined to believe there's something else going on considering I have xDebug on MAMP and I'm not experiencing the same error not having the variable declared on the index.php page. However, this may all be moot since the project files have the variable declared on the index page any way.

That just seems like a "hacky" way of dealing with the issue that would be annoying to need to declare variables on pages that have an included conditional that don't have variables to interact with on said page, especially since on a different development server that isn't the case.

But hey, if it works it works, glad it worked for you.