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 Including the Header

melissa brown
melissa brown
4,670 Points

contact page wont load

i get this error msg when i click on the contact page

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8

i have added the contact.php to the # signed but it still doesnt seem to work.

<html>
<head>
    <title><?php echo "Shirts 4 Mike";?></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"><a href="#">Shirts</a></li>
                <li class="contact"><a href="contact.php">Contact</a></li>
                <li class="cart"><a href="#">Shopping Cart</a></li>
            </ul>

        </div>

    </div>

    <div id="content">```

```<?php include('inc/header.php'); ?>

    <div class="section page">

        <h1>Contact</h1>    

    </div>      

```<?php include('inc/header.php'); ?>

    <div class="section banner">

        <div class="wrapper">

            <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
            <div class="button">
                <a href="#">
                    <h2>Hey, I&rsquo;m Mike!</h2>
                    <p>Check Out My Shirts</p>
                </a>
            </div>
        </div>

    </div>

    <div class="section shirts latest">

        <div class="wrapper">

            <h2>Mike&rsquo;s Latest Shirts</h2>

            <ul class="products">
                <li><a href="#">
                        <img src="img/shirts/shirt-108.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-107.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-106.jpg">
                        <p>View Details</p>
                    </a>
                </li><li>
                    <a href="#">
                        <img src="img/shirts/shirt-105.jpg">
                        <p>View Details</p>
                    </a>
                </li>                               
            </ul>

        </div>

    </div>

</div>

<div class="footer">

    <div class="wrapper">

        <ul>        
            <li><a href="http://twitter.com/treehouse">Twitter</a></li>
            <li><a href="https://www.facebook.com/TeamTreehouse">Facebook</a></li>
        </ul>

        <p>&copy;<?php echo date ('Y');?> Shirts 4 Mike</p>

    </div>

</div>

</body> </html>```

7 Answers

Hey Melissa, thanks for sharing more details. Like I said, "contact.php" should NOT be inside the "inc" directory. "inc" directory is for keeping files with part of code that gets repeated often in other files, like the header part of code gets repeated in "index.php" and "contact.php" so we keep it separate inside the "header.php" file. Purpose is to check the redundant code while keeping it manageable.

In short, move "contact.php" outside "inc" directory, and change the contact link to "contact.php" inside "header.php" file. For now, "inc" directory should have only one file, "header.php".

Your code should look like this:

index.php

<?php include('inc/header.php'); ?>

        <div class="section banner">

            <div class="wrapper">

                <img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
                <div class="button">
                    <a href="#">
                        <h2>Hey, I&rsquo;m Mike!</h2>
                        <p>Check Out My Shirts</p>
                    </a>
                </div>
            </div>

        </div>

        <div class="section shirts latest">

            <div class="wrapper">

                <h2>Mike&rsquo;s Latest Shirts</h2>

                <ul class="products">
                    <li><a href="#">
                            <img src="img/shirts/shirt-108.jpg">
                            <p>View Details</p>
                        </a>
                    </li><li>
                        <a href="#">
                            <img src="img/shirts/shirt-107.jpg">
                            <p>View Details</p>
                        </a>
                    </li><li>
                        <a href="#">
                            <img src="img/shirts/shirt-106.jpg">
                            <p>View Details</p>
                        </a>
                    </li><li>
                        <a href="#">
                            <img src="img/shirts/shirt-105.jpg">
                            <p>View Details</p>
                        </a>
                    </li>                               
                </ul>

            </div>

        </div>

    </div>

    <div class="footer">

        <div class="wrapper">

            <ul>        
                <li><a href="http://twitter.com/treehouse">Twitter</a></li>
                <li><a href="https://www.facebook.com/TeamTreehouse">Facebook</a></li>
            </ul>

            <p>&copy; <?php echo date('Y'); ?> Shirts 4 Mike</p>

        </div>

    </div>

</body>
</html>

contact.php

<?php include('inc/header.php'); ?>

        <div class="section page">

            <h1>Contact</h1>

        </div>

inc/header.php

<html>
<head>
    <title><?php echo "Shirts 4 Mike"; ?></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"><a href="#">Shirts</a></li>
                <li class="contact"><a href="contact.php">Contact</a></li>
                <li class="cart"><a href="#">Shopping Cart</a></li>
            </ul>

        </div>

    </div>

    <div id="content">

Hey Melissa, if the "contact.php" is in the same folder as your index file, try using "./contact.php".

melissa brown
melissa brown
4,670 Points

hi manav, thanks for your reply. The contact.php folder not in the same folder as the index file it is in the inc folder. i tried your suggestion above but it still didnt work,

then you should try "./inc/contact.php".

melissa brown
melissa brown
4,670 Points

didnt work either but i did get a different error msg this time Warning: include(inc/header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\shirts4mike\inc\contact.php on line 1

Warning: include(): Failed opening 'inc/header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\shirts4mike\inc\contact.php on line 1 Contact

Since I don't see your directory structure, it's tough to imagine what's in there but you shouldn't put contact.php inside the inc folder. inc folder should only contain header.php with header text carrying link to contact page like "contact.php" for example. Can you share whats inside your header.php? Chances are you are including it and still forgot to remove the header text from the index.php causing it to duplicate. But again it's all guess unless you share your directory structure and header.php code as well.

melissa brown
melissa brown
4,670 Points

ok thanks

http://imgur.com/aVd1ec6

here is the screenshot and header code

<html>
<head>
    <title><?php echo "Shirts 4 Mike";?></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"><a href="#">Shirts</a></li>
                <li class="contact"><a href="./inc/contact.php">Contact</a></li>
                <li class="cart"><a href="#">Shopping Cart</a></li>
            </ul>

        </div>

    </div>

    <div id="content">```