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

I am using variables for title tag, but it is sending error in the tile tab like /<br /> <b> Notice <b>... like this

I am using variables for title tag, but it is sending error in the tile tab like /<br /> <b> Notice <b>... like this My code for header.php is

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

And my code for suggest.php is

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

Could someone help me in this case, why it's not showing title in the title tab. Thanks

4 Answers

Craig Peckett
Craig Peckett
10,531 Points

Probably a bit late now but even if you click preview on the suggest page it opens the index page hence why your not seeing the title. You have to click on the link to the suggest page to see the title change.

Craig is correct, I just ran into the same issue on this lesson and I tested this with attempting to preview "catalog.php" as well. It behaves as Craig is describing, if you click on the actual page it works fine.

Hi Md,

Your code runs fine for me, locally. I would double check your paths to your include files are correct. Does all the other content, such as your menu, load properly?

Yes it does run locally fine but it is not responding in Workspaces. Anyway, thanks a lot, Mark! Could you suggest some online websites for live project in PHP, especially learning sessions and cookies. Thanks!

I am guessing you didn't declare the variable before including the header. The variable must be declared before including the header.

Tuan Phan
Tuan Phan
10,825 Points

Your code works for me.

Either check again your path or have you save both files before running them.