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

I am certain I have the correct answer for the challenge "Now echo Mike's Name To The Screen" and cannot move forward.

I have also tried a variation where I include all the relevant HTML tags (DOCTYPE, html, h1) and still cannot move forward. Thanks!

index.php
<?php 
$name = "Mike";
?>

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

<!DOCTYPE html>
<html>
  <body>
    <h1><?php echo $name ?></h1>
  </body>
</html> 

This is the other code that I've tried unsuccessfully. Any input as to what's wrong would be appreciated!

2 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

You've almost done it. :) You just need to add a semi colon to your php code block to close the statement. When it comes to syntax PHP can be very strict.

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

<?php echo $name; ?>

Thanks, but unfortunately that also did not work. I have tried

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

<?php echo $name; ?>

...as well as...

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

<!DOCTYPE html>
<html>
  <body>
    <h1><?php echo $name; ?></h1>
  </body>
</html> 

Still not sure what I'm doing wrong?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Try putting both statements into one code block.

This would make sense as the code is probably not picking up the reference to the value in the $name variable as it's in another block.

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

Thanks! that worked

Rich Donnellan
MOD
Rich Donnellan
Treehouse Moderator 27,708 Points

Timothy,

You can include the echo statement in the previous objective's tags (which passed on my end).

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

Hope this helps!

Thanks! that worked