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
willromano
14,714 PointsContact link renders null
I'm in the Build a Simple PHP Application project. After creating the contact.php file I tried to put the link in header.php but when I viewed it in the browser the link was broken. I have checked the name and location of the file and inspected the source with the dev tools. In the html the link was set to null and when I changed it to <a href="contact.php"> it worked! When I reload though, it's set to null again. I think for some reason the php server is rendering the link null. My browser is Firefox 30.0 and I'm running Window 8.1 with XAMPP installed. Here is header.php
<html lang="en-us">
<head>
<title><?php echo "Shirts 4 Mike"; ?></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"><a href="#">Shirts</a></li>
<li class="contact"><a href="header.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<div id="content">
The li with the class contact is the broken one.
(I tried adding the doctype but it still dosn't work. This is the same code as the video and it works when I edit it in the browser. I can also access contact.php from the browser (localhost/shirts4mike/contact.php).)
Thanks
8 Answers
Solomon Scott
20,586 Points<a href="header.php"> to <a href="contact.php">
Sorry my tilde wasn't working
Solomon Scott
20,586 PointsIs your header file an include file? If so then the browser won't be able to render it because there is no closing </body> or </html>. When you redirected it to contact.php it will render the full file with header.php inside of it. Keep it contact.php and it will show the full page.
willromano
14,714 PointsYes, it's an include file. Here's contact.php
<?php include("includes/header.php"); ?>
<div class="section page">
<h1>Contact</h1>
</div>
<?php include("includes/footer.php"); ?>
The tag is incomplete in the video, for some reason it worked there. Should I try deleting the unclosed tags or closing them?
Solomon Scott
20,586 PointsPHP include files won't be rendered by the browser because they are not full files. If you keep the contact.php in the href it should work. When it renders as a HTML file it will read out as if the header.php is already in the contact.php file.
Try this in the header.php:
` <html lang="en-us"> <head> <title><?php echo "Shirts 4 Mike"; ?></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"><a href="#">Shirts</a></li>
<li class="contact"><a href="contact.php">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<div id="content">
`
willromano
14,714 PointsThe fully rendered contact.php file is
<html lang="en-us">
<head>
<title>Shirts 4 Mike</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"><a href="#">Shirts</a></li>
<li class="contact"><a href="#">Contact</a></li>
<li class="cart"><a href="#">Shopping Cart</a></li>
</ul>
</div>
</div>
<div id="content">
<div class="section page">
<h1>Contact</h1>
</div>
</div>
<div class="footer">
<div class="wrapper">
<ul>
<li><a href="http://twitter.com/treehouse">Twitter</a></li>
<li><a href="https://www.facebook.com/TeamTreehouse">Facebook</a></li>
</ul>
<p>©2014 Shirts 4 Mike</p>
</div>
</div>
</body>
</html>
I tried your code but it didn't work for me for some reason.
Solomon Scott
20,586 PointsTo fix the null issue, change
'<li class="contact"><a href="header.php">Contact</a></li>'
to
'<li class="contact"><a href="contact.php">Contact</a></li>'
That should keep the browser from rendering the link as null
Solomon Scott
20,586 PointsChange
<li class="contact"><a href="header.php">Contact</a></li>
to
<li class="contact"><a href="contact.php">Contact</a></li>
Solomon Scott
20,586 Points<a href="header.php"> to <a href="contact.php">
willromano
14,714 PointsI was changing things and it works now, I don't really know why because it seems the same. What did you mean by changing 'Contact' to 'Contact', aren't they the same?
Solomon Scott
20,586 PointsThat was my mistake, it was supposed to render markdown but I forgot the proper markdown code.
willromano
14,714 Pointswillromano
14,714 PointsYes, I made the mistake of putting
header.phpinstead ofcontact.php. How did I miss that? Well, at least it's solved now.Thanks for spotting, Will