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

Alejandro Jerez
Alejandro Jerez
10,987 Points

Whats Wrong? Build a Basic PHP Website, Working with $_GET variables

I followed the video and when I click on the "Suggest" and "Books" part of the site I get this: Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/catalog.php on line 11

'''php

<?php $pageTitle = 'Full Catalog';

if(isset($_GET["cat"])){

if ($_GET["cat"] == "books"){ $pageTitle = "Books"; }else if($_GET["cat"] == "movies"){ $pageTitle = "Movies"; }else if($_GET["cat"] == "music"{ $pageTitle = "Music"; } } include("Includes/header.php"); ?>

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

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

'''

3 Answers

Since the pasted in version didn't appear to keep your version very well, I redid it below, and fixed it up.

<?php
$pageTitle = 'Full Catalog';

if (isset($_GET["cat"])) {

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

} 

include("Includes/header.php"); 

include("Includes/footer.php"); 
?>

But I have a question, why do you need the if...else if... etc. Why not just this?

<?php
if (isset($_GET["cat"])) {
    $pageTitle = $_GET["cat"] ; 
}
?>

and send the cat through in the query string capitalized. Or use the PHP ucfirst method pn receipt of cat.

http://php.net/manual/en/function.ucfirst.php

(PHP 4, PHP 5, PHP 7) ucfirst β€” Make a string's first character uppercase

Because if they send through ?cat=Sausages that's what you'll get as a title even though there aren't any sausages in your library.....

I am having the exact same issue. Any help would be great.

Enrico Buntsel
Enrico Buntsel
11,038 Points

I have same issue, can you please help?