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

Ben Os
Ben Os
20,008 Points

Unexpected "greater than" in line 7 ? But I used only what I need to open&close!

Hello, each time I try to test each file in my workspace I get the error:

Parse error: syntax error, unexpected '<' in /home/treehouse/workspace/index.php on line 7

I checked the code 3 times and espcially this line and it seem okay --- Opening and close tags are in place, the class is setted okay (I didn't change it), and there is a closing tag. Would be thankful for the teachers' advice about this.

Here is my index.php code snippet:

<?php

$pageTitle = "Home sweet home";

include("inc/header.php");

<div class="section catalog random">

            <div class="wrapper">

                <h2>May we suggest something?</h2>

                                <ul class="items">
                    <li><a href="details.php?id=201"><img src="img/media/forest_gump.jpg" alt="Forrest Gump"><p>View Details</p></a></li><li><a href="details.php?id=204"><img src="img/media/princess_bride.jpg" alt="The Princess Bride"><p>View Details</p></a></li><li><a href="details.php?id=302"><img src="img/media/elvis_presley.jpg" alt="Elvis Forever"><p>View Details</p></a></li><li><a href="details.php?id=303"><img src="img/media/garth_brooks.jpg" alt="No Fences"><p>View Details</p></a></li>                              
                </ul>

            </div>

        </div>

include("inc/footer.php");

?>

Other code snippets:

Catalog.php:

<?php

$pageTitle = "Full catalog!";

include("inc/header.php");

<div class="section page">
  <h1>Hello world!</h1>
</div>

include("inc/footer.php");

?>

Suggest.php:

<?php

$pagetitle = "$pageTitle";

include("inc/header.php");

<div class="section page">
  <h1>Suggest a mdeia item!</h1>
</div>

<?php include("inc/footer.php"); 

?>
header.php:

<?php

<html>
<head>
  <title><$pageTitle = "Suggest a media item";</title>
    <link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>

    <div class="header">

        <div class="wrapper">

            <h1 class="branding-title"><a href="./">Personal Media Library</a></h1>

            <ul class="nav">
                <li class="books"><a href="catalog.php?cat=books">Books</a></li>
                <li class="movies"><a href="catalog.php?cat=movies">Movies</a></li>
                <li class="music"><a href="catalog.php?cat=music">Music</a></li>
                <li class="suggest"><a href="suggest.php">Suggest</a></li>
            </ul>

        </div>

    </div>

    <div id="content">

    ?>

footer.php:

    </div> <!-- Close later! -->

    <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") . "Personal Media Library"; ?></p>

        </div>

    </div>

</body>
</html>

2 Answers

Hi Ben,

Looks like the error is in the header.php

You dont need to wrap the full code in a php tag and the title tag has couple issues going on. I have posted the changes below to help :

<html>

    <head>
        <title><?php echo $pageTitle; ?></title>
        <link rel="stylesheet" href="css/style.css" type="text/css">
    </head>

    <body>

        <div class="header">

            <div class="wrapper">

                <h1 class="branding-title"><a href="./">Personal Media Library</a></h1>

                <ul class="nav">
                    <li class="books<?php if ($section == "books") {echo " on";} ?>"><a href="catalog.php?cat=books">Books</a></li>
                    <li class="movies<?php if ($section == "movies") {echo " on";} ?>"><a href="catalog.php?cat=movies">Movies</a></li>
                    <li class="music<?php if ($section == "music") {echo " on";} ?>"><a href="catalog.php?cat=music">Music</a></li>
                    <li class="suggest<?php if ($section == "suggest") {echo " on";} ?>"><a href="suggest.php">Suggest</a></li>
                </ul>

            </div>

        </div>

        <div id="content">

I am also noticing in all the files you are wrapping the full html code in php tags, you only need to wrap php dependent code in php tags.

Here is a snapshot of my workspace from an early part in the course about were you are I think

In regard to debugging the snapshot feature of workspaces is great, you can let someone see all your code simply by pasting in a link. To do that click the camera icon in the to right to get the link. If you prefer working locally this can still be utalised but with a slightly longer process.

For example:

your site is stored in a folder "my-site.dev" on your pc

you can create a new workspace(with correct environment for the code i.e. php) and then upload the full folder. this will give you access to the snapshot feature again, no more chopping up code and markdown in the questions :)

Hope this helps,

Craig

Ben Os
Ben Os
20,008 Points

Craig, I've marked your answer as best and thumbed up!

I do have another un-related issue, not with PHP (I already went forward to do other PHP tasks) but with the CSS: I suddenly don't have any CSS in my site, besides images and I didn't even touch the CSS or the link to it in header.php. Here is a link to the relevant thread:

https://teamtreehouse.com/community/my-catalog-items-appear-as-a-long-list-and-suddenly-there-is-no-css-in-the-site

Hi Ben,

Can you post a link to a snapshot of your workspace using the camera icon in the top right? When you post a link to a workspace but dont have the code open anymore unfortunately others cant view the workspace.

If you can post a snapshot id be happy to take a look over the code :)

Craig

Ben Os
Ben Os
20,008 Points

Hello there and blessings Craig!, I've edited the question and added the code in a snippet,

Ben,

Hi Ben,

Sorry to be a pain, but with PHP the problem could be coming from one of the includes to so can you post them in as well drop them in the original question if that's easiest :)

Craig

Ben Os
Ben Os
20,008 Points

Putted the other 4 snippets. For times I would work locally, you might also have any tips for me how to debug shared code sites in a direct way instead of going file after file? (BTW when I copied the files to my local machine with WAMP I still had the same error so it's very frustrating)...

Hi ben,

So after updating all your files to match the ones in the link above on the snapshot you still have the error ?

Craig

Ben Os
Ben Os
20,008 Points

I didn't do anything since yesterday --- The snippets I uploaded to here are the same as in my workspace.

I still have the error.

No problem, please take a look here at the code and you will be able to spot the errors as mentioned in the answer above with the snippet of my header.php on :)

Craig

Ben Os
Ben Os
20,008 Points

Hi Craig! Thanks from all heart for your graceful help!

Indeed, after I've implemented what you wrote the site returned to work fine.

I've internalized 2 important rules:

1) I should open a new php segment for each independent php codepiece in the file.

2) I should put the php tags either solely or inside HTML tags, but NEVER as wrapping the whole dodumcent and NEVER as wrapping HTML tags.