Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP PHP Basics (Retired) PHP Data & Structure PHP Variables

Bart Poelstra
Bart Poelstra
2,385 Points

I'm trying to echo mike's name in the output. So I thought: <?php echo $name ?> But that seems incorrect.

Hope someone can help! :)

index.php
<?php 

  $name = "Mike";

?>

<?php echo $name ?>

2 Answers

I just took the challenge and passed with this code:

<?php
$name = "Mike";
echo $name;

I see a couple of things that might be preventing passing the challenge. Most importantly, you are missing the ; after your echo statement. Second, you do not not need to close and open your php between the variable and echo.

You may notice that I did not close my php. You do not have to close if all the code on the page is php.

Jeff Lemay
Jeff Lemay
14,266 Points

This challenge comes up frequently. They want all your code in a single php block (like Ted's answer, although I always close my php no matter what just to be safe).

Your code is "correct", just not what the challenge wants.

In the later php courses they say it is best practice to not close if you can because of white space issues.

Jeff Lemay
Jeff Lemay
14,266 Points

Hmm I'll have to check that out. Thanks for the info!