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 Using Variables for the Title Tag

David Bayley
David Bayley
10,312 Points

Getting undefined variable error message

Followed steps in video but when I preview suggest.php I get Undefined Variable notice instead of the actual page title:

SUGGEST.PHP

<?php $pageTitle = "Suggest a Media Item";

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

<div class="section page"> <h1>Suggest a Media Item</h1> </div>

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

HEADER.PHP

<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"><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">

2 Answers

Sean Randle
Sean Randle
5,804 Points

You are probably viewing the home page as in the index.php file. Title for the homepage has not been set at this stage of the course hence you are seeing the error. Try clicking on the suggest tab in the nav menu and see if your title shows up or not?

Hi David,

If you are using workspaces please make sure it saved and double check it. I just did it and it took a few moments for my suggest.php to save.