Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Basic PHP Website Building a Media Library in PHP Using Variables for the Title Tag

Will Albertsen
Will Albertsen
13,155 Points

variable $pageTitle undefined

For some reason, the variable $pageTitle is returning undefined up in the tab. No idea why. Here is the code.


$pageTitle = "Suggest a Media Item";
include("inc/header.php"); ?>

<div class="section page">
  <h1>Suggest a media item.</h1>

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


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

Here is what it says up in the tab when I run this:

<br /> <b>Notice</b>: Undefined variable: pageTitle in <b>/home/...

That's all I could read

3 Answers

1) Are you sure you aren't looking at index.php but if so that you have assigned a value to $pageTitle before include("inc/header.php"); in index.php?

2) If that is all of your code for header.php you can't navigate to suggest.php from the start page since the links are included in the header. However you can add /suggest.php to the address bar to load the suggest page. For example mine looks like this:


Doing so you'll notice the tab displays "Suggest a Media Item" as you have in the code.

Will Albertsen
Will Albertsen
13,155 Points

Thank you so much for your response. I have since resolved the issue although I never knew figured out exactly what the problem was :) I'm sure I probably misread some of that code when I pasted it in.

Undefined here too. Totally follows the video and get same problem. Don't know how to fix.