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 trialEric Huffman
12,472 PointsPHP 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.
6 Answers
James Gill
Courses Plus Student 34,936 PointsEric,
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
17,172 PointsYou 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.
banu babanu
8,152 PointsTry ; after echo $name
Eric Huffman
12,472 PointsI tried this suggestion, but was still not able to pass the challenge.
James Turner
1,707 PointsI have the same problem! Josh tried your suggestion, it didnt like it
<?php $name = "Mike"; echo $name; ?>
Josh Alling
17,172 PointsOdd. I just copied your code into the challenge, and it worked for me.
Eric Huffman
12,472 PointsSo 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.
James Turner
1,707 Pointsweird I use firefox. I guess i will have to try something else.
Ryan Coakley
1,005 PointsThis 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.
Jason Anello
Courses Plus Student 94,610 PointsHi 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
1,005 Points<?php
$name = "Mike";
echo $name;
?>
Jason Anello
Courses Plus Student 94,610 PointsHi 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'
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsHi 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.