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 trialmarkdames
Front End Web Development Techdegree Student 9,614 PointsWhat I am doing wrong?
I get the following message when I load the page: ! ) Notice: Undefined variable: section in C:\wamp\www\php\inc\header.php on line 17 Call Stack #TimeMemoryFunctionLocation 10.0010131960{main}( )..\index.php:0 20.0010134264include( 'C:\wamp\www\php\inc\header.php' )..\index.php:3 ">
Notice: Undefined variable: section in C:\wamp\www\php\inc\header.php on line 18 Call Stack #TimeMemoryFunctionLocation 10.0010131960{main}( )..\index.php:0 20.0010134264include( 'C:\wamp\www\php\inc\header.php' )..\index.php:3 ">
Code:
<html> <head> <title><?php echo $pageTitle; ?></title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="favicon.ico"> </head> <body>
<div class="header">
<div class="wrapper">
<h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>
<ul class="nav">
<li class="shirts <?php if($section == "shirts") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<div id="content">
6 Answers
Gloria Dwomoh
13,116 PointsThanks for finally posting your code. In your index, above include, add this - $section = "home";
Robert Richey
Courses Plus Student 16,352 PointsHi Mark,
Are you defining $section before including header.php on each page?
<?php
$pageTitle = "Mike's Full Catalog of Shirts";
$section = "shirts";
include('./inc/header.php');
?>
Gloria Dwomoh
13,116 PointsTry removing the semicolon
<?php echo $pageTitle; ?>
to
<?php echo $pageTitle ?>
If that doesn't help. Let us know.
markdames
Front End Web Development Techdegree Student 9,614 PointsHello Gloria,
Unfortanly It didn't helped. I still get the same error messages on the index page. The contact and the shirts page are working fine.
Gloria Dwomoh
13,116 PointsCan you paste the whole code?
Blaize Pennington
13,879 PointsIt looks like your issue is you have not defined the variable $section
anywhere. So PHP is trying to test your if statement, but can't find $section
so it is printing out an error.
If you show me both your index.html code and your full header.php code I may be able to figure out exactly where this definition is failing.
markdames
Front End Web Development Techdegree Student 9,614 PointsHello Blaize,
Index:
<?php $pageTitle = "Unique T-shirts designed by a frog"; include('inc/header.php'); ?>
<div class="section banner">
<div class="wrapper">
<img class="hero" src="img/mike-the-frog.png" alt="Mike the Frog says:">
<div class="button">
<a href="#">
<h2>Hey, I’m Mike!</h2>
<p>Check Out My Shirts</p>
</a>
</div>
</div>
</div>
<div class="section shirts latest">
<div class="wrapper">
<h2>Mike’s Latest Shirts</h2>
<ul class="products">
<li><a href="#">
<img src="img/shirts/shirt-108.jpg">
<p>View Details</p>
</a>
</li><li>
<a href="#">
<img src="img/shirts/shirt-107.jpg">
<p>View Details</p>
</a>
</li><li>
<a href="#">
<img src="img/shirts/shirt-106.jpg">
<p>View Details</p>
</a>
</li><li>
<a href="#">
<img src="img/shirts/shirt-105.jpg">
<p>View Details</p>
</a>
</li>
</ul>
</div>
</div>
<?php include('inc/footer.php'); ?>
Header:
<html> <head> <title><?php echo $pageTitle ?></title> <link rel="stylesheet" href="css/style.css" type="text/css"> <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,700" type="text/css"> <link rel="shortcut icon" href="favicon.ico"> </head> <body>
<div class="header">
<div class="wrapper">
<h1 class="branding-title"><a href="./">Shirts 4 Mike</a></h1>
<ul class="nav">
<li class="shirts <?php if($section == "shirts") { echo "on"; } ?>"><a href="shirts.php">Shirts</a></li>
<li class="contact <?php if ($section == "contact") { echo "on"; } ?>"><a href="contact.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<div id="content">
Blaize Pennington
13,879 PointsYou have not defined $section in your index.html file, and this is why you are getting an error. Right below $pageTitle = "Unique T-shirts designed by a frog";
type $section = "shirts";
. This should fix your problem.
markdames
Front End Web Development Techdegree Student 9,614 Pointsmarkdames
Front End Web Development Techdegree Student 9,614 PointsGreat! That solved the problem. Thanks!
Master Marketing
1,200 PointsMaster Marketing
1,200 PointsYou're a life saver! Thanks! c:
Gloria Dwomoh
13,116 PointsGloria Dwomoh
13,116 PointsMaster Marketing, thanks. I'm glad to save lives, haha ^_^ You're welcome.
Master Marketing
1,200 PointsMaster Marketing
1,200 PointsLol! You're welcome! I have been going through this problem for a while now. So glad we could get a lot of help in the treehouse forums. Thanks again! ^^