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 (2018) Listing and Sorting Inventory Items Displaying Categories

Working on displaying specific categories for each page and all the sudden I am getting this error when refreshing

"Books", "Movies" and "Music" pages...

Parse error: syntax error, unexpected '$pageTitle' (T_VARIABLE) in /home/treehouse/workspace/catalog.php on line 5

<?php include("inc/data.php"); include("inc/functions.php")

$pageTitle = "Full Catalog"; $section = null;

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

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

<div class="section catalog page">

  <div class="wrapper">

      <h1><?php echo $pageTitle; ?></h1>

      <ul class="items">
        <?php
        $categories = array_category($catalog,$section);
        foreach ($categories as $id) {
           echo get_item_html($id,$catalog[$id]);
        }
        ?>  
    </ul>

 </div>

</div>

2 Answers

Benjamin Payne
Benjamin Payne
8,142 Points

Hey Amber,

Right after include("inc/functions.php") you are missing a semi-colon. Just some friendly advice...try to keep individual statements on their own line. This will help you spot syntax errors like this. If you can, try and configure your editor to warn you when you are breaking a specific coding style like PSR1/2. This will help as well.

Thanks,

Ben

Oh wow, thank you, I can't believe I missed that! They are on separate lines in the workspace but when I copied it over it combined them. Haven't figured out how to get the actual workspace screen over to "get help". How do you configure the editor?

Benjamin Payne
Benjamin Payne
8,142 Points

Gotcha...I try and use a separate editor whenever possible. Workspaces is nice but its functionallity is limited and i don't think it does syntax and error highlighting.