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've typed in <?php echo $name ?> and I can't pass this stage? I have tried putting a !DOCTYPE html, body tags too.

I've tried filling ih text editor to pass the quiz and it says its incorrect. I can'r figure out how its incorrect as I've put

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

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

Please could you explain how I'm doing this wrong?

2 Answers

Joseph Greevy
Joseph Greevy
4,990 Points

You dont have a semi colon after $name and why did you put a <!DOCTYPE html> in I think thet code should be

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

Thanks Joseph,

I was just under the impression the preview window would need to be in html to read it so I made a body and paragraph tag too!

Joseph Greevy
Joseph Greevy
4,990 Points

ye I understand it might be later on in the course but you wont access it like that. You will just echo out tags like so

echo "<html>"
echo "<div>"

or adding php tags into an element

<div>
     <?php echo $name; ?>
  </div>

Yeah I get you now, Just threw me off a little as the previous examples it was inside body tags etc, thanks for the quick response :)