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

Karalyn Heath
Karalyn Heath
18,033 Points

Using Variables for the Title Tag not working

Getting Undefined variable notice on $pageTitle while trying to preview in Workspace. Not sure what I'm missing. Here are my header.php and suggest.php files.

<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">
<?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"); ?>

1 Answer

Karalyn Heath
Karalyn Heath
18,033 Points

Working now! Possibly just a Workspaces bug...