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

Ader Reynoso
Ader Reynoso
4,968 Points

message

after made the exercise everything is ok in contact and shirt pages, but not the same in index i received this messages: ( ! ) Notice: Undefined variable: section in C:\wamp\www\shirts4mike\inc\header.php on line 17 Call Stack #TimeMemoryFunctionLocation 10.0007668168{main}( )..\index.php:0 20.0013673280include( 'C:\wamp\www\shirts4mike\inc\header.php' )..\index.php:3 ">Shirts ( ! ) Notice: Undefined variable: section in C:\wamp\www\shirts4mike\inc\header.php on line 18 Call Stack #TimeMemoryFunctionLocation 10.0007668168{main}( )..\index.php:0 20.0013673280include( 'C:\wamp\www\shirts4mike\inc\header.php' )..\index.php:3 ">Contact Why¿? What am I doing wrong?

Thanks for your help!

Ader.

8 Answers

Craig MacIntyre
Craig MacIntyre
9,943 Points

It's difficult to tell without looking at the code in the 'header.php' file. Could you show us?

Hi ya, It is complaining about an unknown variable called section .. do share the code and we might be able to help

Ader Reynoso
Ader Reynoso
4,968 Points

Thanks Friends! this is my code <html> <head> <title><?php echo $titleName; ?></title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="favicon.ico"> </head> <body>

<div class="header">

    <div class="wrapper">

        <h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>

        <ul class="nav">
            <li class="shirts <?php if ($section == "shirt") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
            <li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li>
            <li class="cart"><a href="#">Shopping Cart</a></li>
        </ul>

    </div>

</div>
<div id="content">
Craig MacIntyre
Craig MacIntyre
9,943 Points

Try changing:

if ($section == "shirt")

to

if ($section == "shirts")

Have you initialised the section variable, after title you need to initiate the section variable. You need to initialize the section as $section = "shirt"; right after the title tag on the shirts page and same on the other pages as well

Ader Reynoso
Ader Reynoso
4,968 Points

Sorry Friends! I've done the changes and continue the same trouble <?php $titleName = "Contacto"; $section = "contact"; include('inc/header.php'); ?>

and I've made the change instead of "shirt" for "shirts"

Thanks for your help!

Hmmm, ok the only thing that makes sense is, you are inside the double quotes and then again using the double quotes... Therefore PHP is confused even the HTML for it matters. let me show you

<li class="shirts <?php if ($section == "shirt") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>

// <li class="shirts on`"><a href="shirts.php">Shirts</a></li>  .... This is what you need right, Now then
// If you look at your code the class bit where you say ;

<li class="shirts <?php if ($section == "shirt") { echo "on"; } ?>">
// You can see that your shirt variable is wrapped in double quotes. as soon as the double quotes start
// thats the end for the php parsing engine.. hence, change your code as below

<li class="shirts <?php if ($section == 'shirt') { echo 'on'; } ?>">

// Make sure that whenever there is a html double quote you declare your php variables in single
// quotes that the easy way. alternatively you can do as follow

<li class="shirts <?php if ($section == \"shirt\") { echo  \"on\"; } ?>">

//In the above method you are escaping the double quotes

Hope that helps. let me know if it works. cheers

Ader Reynoso
Ader Reynoso
4,968 Points

I really appreciate your help! I tried the two methods and didn't works in face I download the exercise and copy an paste the code and exactly the same message: ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined variable: section in C:\wamp\www\shirts4mike\inc\header.php on line 17 Call Stack #TimeMemoryFunctionLocation 10.0014668504{main}( )..\index.php:0 20.0026673616include( 'C:\wamp\www\shirts4mike\inc\header.php' )..\index.php:3 "> and ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined variable: section in C:\wamp\www\shirts4mike\inc\header.php on line 18 Call Stack #TimeMemoryFunctionLocation 10.0014668504{main}( )..\index.php:0 20.0026673616include( 'C:\wamp\www\shirts4mike\inc\header.php' )..\index.php:3 ">

when i run the orginal files, every runs perfectly but at this point of my exercise dont.

Thanks so much for your help!