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

Why does this code not work?

Why does the output not show "Mike"?

<?php

$name = "Mike";

?>

<?php echo $name ?>

4 Answers

Jonah,

You'll need to put the variable and the echo statement inside the same php tags, and add a semicolon after the echo statement. So:

<?php

$name = "Mike";
echo $name; 

?>

Sometimes, what you're doing will work within two php tags, but I haven't seen it work in the Treehouse code editor.

hope that helps, -james

Still doesn't work. This is in the PHP Basics class on the PHP Variables challenge

Thanks James! It works!

Excellent! As I progress, the most common errors I make are small syntax errors (like, say, omitting semicolons). When in doubt (and to save time), check that stuff first.

no semicolon after $name Should be <?php echo $name; ?>