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

Issues with my php code

<?php

$name = "Mike";

?>

<?php echo $name ?>

This is my code for a PHP challenge asking me to echo the name. Unless I am mistaken this should be right as I even went back just to watch the video and copy what the instructor did. Can anyone please let me know if I have made some error and I just can't see it?

EDIT: I did put the echo name into the question just for some reason it's not being displayed on this page

Your echo command is missing. You are just creating a variable $name with the value of "Mike", but you are not echoing the variable.

Seems like I forgot to copy the entire thing:

<?php

$name = "Mike";

?>

<?php echo $name ?>

Fixed markdown of php code

3 Answers

Andrew,

The issue is that the challenge is expecting only 1 php code block. With 1 block, and your code, it will pass - but fails when using 2 code blocks. Just echo the name right below the variable assignment.

Cheers!

oh right. Thanks for that, sorry for all the trouble there

No trouble at all. Thanks for your patience!

Hi Andrew,

The only thing I see right now that needs fixing is that each statement needs to end with a semi-colon.

<?php echo name ?>

// needs to be

<?php echo name; ?>

If that doesn't solve the issue, can you please paste a link to the challenge you're working on?

Kind Regards

See in the video the instructor does say and as far as I am aware of PHP single line statements don't normally require the semi-colon but I have tried adding it just to be sure it wasn't just me being incorrect and I'm still getting nothing. I tried using the preview option with a number of outputs and it's echoing nothing.

https://teamtreehouse.com/library/php-variables here is the link

One thing to keep in mind is the PHP does not appear to output to your browser in the code challenges. It may be useful to create a workspace and test your code there to see how it acts.

What you have done so far is assign the value of "Mike" to the variable $name. That won't immediately return any information to the browser; for that you need to use the PHP command echo followed by your variable name.

Edit: After your echo statement you need to include a semicolon to signal to the server that your line ends.