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 (Retired) PHP Data & Structure PHP Variables

PHP Data & Structure challenge issues

<?php

$name = "Mike";

?>

<h1><?php echo $name ?></h1>

This is the code I type into the editor, for the challenge. The challenge is to echo someone's name to the screen. I'm wondering if this is an issue on Treehouse's side because I can't see anything wrong with the syntax.

Hi Eric,

I don't think there is anything wrong with your code. It works fine locally.

I think this challenge simply isn't set up to accept two separate php code blocks.

I agree with Josh Alling that it would be better practice to have one php block. If you're going to have 2 consecutive php statements then I think there isn't much point in closing and opening a new php block.

I think you would want to do that if you needed to output some straight html before echoing the $name variable.

6 Answers

Eric,

It's a scope problem. If you put both the variable and the echo statement inside the same php block, it'll work.

Josh Alling
Josh Alling
17,172 Points

You could try putting the echo $name; line directly under the $name = "Mike"; line within the first <?php ?> block. It's a better practice to keep your code organized in this way.

Try ; after echo $name

I tried this suggestion, but was still not able to pass the challenge.

I have the same problem! Josh tried your suggestion, it didnt like it

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

Josh Alling
Josh Alling
17,172 Points

Odd. I just copied your code into the challenge, and it worked for me.

So I found the solution, or close enough. I opened up a different browser, Firefox, and used this: <?php

$name = "Mike";

echo $name;

?>

Worked just fine. Thanks for the suggestions guys.

weird I use firefox. I guess i will have to try something else.

Ryan Coakley
Ryan Coakley
1,005 Points

This question is ridiculous. I have tried doing it the way we learned in the video and the way the person above stated. I even pasted the code in a workspace and my output is "Mike". This is frustrating and needs fixing asap.

Hi Ryan,

You can post the code you're trying if you want someone to take a look.

I've tried the challenge again and it seems to be working fine right now.

Ryan Coakley
Ryan Coakley
1,005 Points

<?php

$name = "Mike";

echo $name;

?>

Hi Ryan,

When pasting in your code here it produced 2 blank lines before the starting php tag. I discovered that this extra whitespace causes the challenge not to pass.

The opening php tag needs to be the 1st line and there can't be even a single space at the beginning.

Did you by any chance happen to have whitespace before your opening php tag when attempting the challenge?

I suspect that the whitespace before counts as output to the page and the challenge is looking for 'Mike' right at the beginning of the output. It's not expecting newline characters or spaces to appear before 'Mike'