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

About 'Creating Menu and Footer' Lesson

Hi,

I started php lessons today. But, I have a problem about this lessons :

http://teamtreehouse.com/library/programming/build-a-simple-php-application/creating-the-menu-and-footer

I understand using variable and if conditional structures. I added some php codes on header.php for adding 'on' css selection. Here my header.php:

<html>
<head>
    <title><?php echo $pageTitle; ?></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=="shirts") {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">

And also adding

$section = "contact"; on contact.php $section="shirts"; on shirts.php.

This codes absolutely work 'shirts' and 'contact' navigation menu for 'underlined' when I clicked (or visited these pages)

But when I go to the homepage (home.php), I got this problem:

http://j1310.hizliresim.com/1g/j/tmpft.jpg (screenshot about problem)

I added

$section="";

code on index.php php area for fix this this problem. And it's worked. But I don't understand this situtation... Can anyone help me ?

I'm sorry for my terrible English :s

Thanks.

2 Answers

My guess is that when the server doesn't find the $section variable on the home page, it freaks out.

PHP is a very sensitive language. Unlike HTML, and CSS, and somewhat Javascript which will try to work with an error. If PHP has an error either part of the page or the whole page will not display correctly.

Hope that answers your problems.

Thank you. When I add $section = ""; every page, this problem solved.