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

PHP Basics - Challenge 2

Part 1 asks to define a PHP variable name, for mike. Got that.

Part 2 asks me to echo mike to the screen - not sure what i'm doing wrong here? I've tried <?php echo "Mike" ?> and <?php echo $name ?> those exact lines of code work in my workspaces as I follow from the video...

What gives?

index.php
<?php 

$name = "Mike";

?>

<?php echo $name ?>

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

Eric,

The challenge is failing because you created a second PHP code block for your echo statement, when it didn't want you to. It simply wants you to put the echo statement in the same code block that you created to house the variable for "Mike".

You have this:

<?php 

$name = "Mike";

?>

<?php echo $name ?>

And while, technically, that is not incorrect and would run just fine elsewhere, it will not pass the challenge here based on the checks that their system is making to see if you got the answer correct. You want:

<?php 

$name = "Mike";

echo $name;

?>

These code challenges can be very particular about what they will accept, so always try every little tiny thing to fix the errors, however stupid they might seem :p

Oh, and don't forget to add a semi-colon after your echo statement! Always officially end your statements!

Happy coding!

Erik

Thanks Erik!