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 Basic PHP Website Building a Media Library in PHP Working with _GET Variables

Patrick Johnson
Patrick Johnson
9,505 Points

I'm getting a Parse error on line 6. It looks like my code is identical.

Hi my code looks identical to the code Alena has demonstrated yet I'm receiving this error:

Parse error: syntax error, unexpected '}' in /home/treehouse/workspace/catalog.php on line 6

line 6 is where the first else if starts

<?php 
$pageTitle = "Full Catalog";

if ($_GET["cat"] == "books") {
 $pageTitle = "Books" 
} else if ($_GET["cat"] == "movies") {
 $pageTitle = "Movies" 
} else if ($_GET["cat"] == "music") {
 $pageTitle = "Music" 
}

include("inc/header.php"); ?>   

<div class="section page">
<h1><?php echo $pageTitle; ?></h1>
</div>


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

2 Answers

Hi Patrick!

You're missing the semicolons on each of your "$page_tiitle = [category]" lines...

That section should look like this:

                if ($_GET["cat"] == "books") {
                    $page_title = "Books";
                } else if  ($_GET["cat"] == "movies") {
                    $page_title = "Movies";
                } else if  ($_GET["cat"] == "music") {
                    $page_title = "Music";
                }

I hope that helps.

BTW, I decided to refactor Alena's code a bit in order to keep all the header-related code in the header.php file.

So my header.php file now looks like this:

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">

    <?php
        $page_name = basename($_SERVER['PHP_SELF'], '.php');
        switch ($page_name) {
            case "catalog":
                $page_title = "Full Catalog";

                if (isset($_GET["cat"])) {
                    if ($_GET["cat"] == "books") {
                        $page_title = "Books";
                    } else if  ($_GET["cat"] == "movies") {
                        $page_title = "Movies";
                    } else if  ($_GET["cat"] == "music") {
                        $page_title = "Music";
                    }
                }

                break;

            case "suggest":
                $page_title = "Suggest Media";
                break;
            default: // index.php
                $page_title = "Media Library";
        }
        echo "<title>" . $page_title . "</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">

And so now, so far, in the course, both my suggest.php file and my catalog.php file look like this:

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

<div class="section page">
     <h1><?php echo $page_title; ?></h1>
</div>

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

Again, I hope that helps!

Stay safe and happy coding!

Patrick Johnson
Patrick Johnson
9,505 Points

Hey Peter! Thanks a bunch. That helped tremendously.

You're welcome!

Now my header.php file looks like this:

<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">

    <?php
        $page_name = basename($_SERVER['PHP_SELF'], '.php');
        switch ($page_name) {
            case "catalog":
                $page_title = "Full Catalog";
                $section = null;

                if (isset($_GET["cat"])) {
                    if ($_GET["cat"] == "books") {
                        $page_title = "Books";
                        $section = "books";
                    } else if  ($_GET["cat"] == "movies") {
                        $page_title = "Movies";
                      $section = "movies";
                    } else if  ($_GET["cat"] == "music") {
                        $page_title = "Music";
                      $section = "music";
                    }
                }

                break;

            case "suggest":
                $page_title = "Suggest Media";
                $section = "suggest";
                break;
            default: // index.php
                $page_title = "Media Library";
                $section = null;
        }
        echo "<title>" . $page_title . "</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">

And I didn't have to update the other three files at all!?! (And it works just fine!?!)