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 PHP Basics PHP on the Web Including PHP

Miguel Nunez
Miguel Nunez
3,266 Points

Answer to this code challenge so I can study this.

Within the current directory, I have created a file named favorites.php that displays a few of my favorite things. Add the php code blocks and include that file so that my favorite things display below the heading.

<html> <head> <title>A Few of My Favorite Things</title> </head> <body> <h1>A Few of My Favorite Things</h1> </body> </html>

This is my answer don't know why i'm getting this wrong.

<html> <head> <title>A Few of My Favorite Things</title> </head> <body> <?php include 'inc/favorites.php';?> <h1>A Few of My Favorite Things</h1> </body> </html>

index.php
<html>
<head>
<title>A Few of My Favorite Things</title>
</head>
<body>
<h1>A Few of My Favorite Things</h1>

</body>
</html>

8 Answers

Matthew Carson
Matthew Carson
5,965 Points

Your include function should be on line 7, below the <h1>.

Also, the file is located in the same directory as the .html file. It isn't in an inc/ directory.

On line 7 of the challenge:

<?php include 'favorites.php'; ?>
Leah Haist
Leah Haist
20,547 Points

This is the correct answer: <?php include('inc/favorites.php'); ?>

<?php include 'favorites.php'; ?>

<?php include 'inc/favorites.php'; ?> GOES ON LINE 8 NOT 7!

<html> <head> <title>A Few of My Favorite Things</title> </head> <body> <h1>A Few of My Favorite Things</h1> <?php include 'inc/favorites.php';?> </body> </html>

I know this is old but I am so confused why we need the ; when it runs just fine without. Even in the work that we did in index.php project prior to the challenge, it was never instructed to use the ;. UGHHHHHHHH -__-

<?php include 'favorites.php'; ?>

<?php include 'favorites.php'; ?> not correct

<?php include 'inc/favourites.php'; ?> this is taken as wrong. What is the correct way

<html> <head> <title>A Few of My Favorite Things</title> </head> <body> <h1>A Few of My Favorite Things</h1> <?php include 'inc/favorites.php';?> </body> </html>