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

Having a problem with PHP Basics Code Challenge: PHP Variables

I have run into a problem with one of the code challenges in PHP Basics. The first part of the challenge asks me to set up a variable in PHP $name = "Mike";

This works out, but the second part is where I'm stuck. It asks me to set up index.php so that it can echo the string in my $name variable.

This is my code below. I believe that it is correctly expressed, but the code challenge editor doesn't register "Mike." Am I missing something?

<?php 
$name = "Mike";

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

</html>

4 Answers

In the challenge they don't ask to set up index.php... just to print the name. So don't put any html, just add the printing statement to your code.

That worked out. I suppose I was jumping ahead of myself. Thank you very much for your help.

Your echo $name is missing something... (wink)

One of the tutorials before this challenge mentioned that it was alright to not place a semi colon after a php statement as long as it was only one statement. I realize that it's best to simply put the semi colon after each statement regardless.

However, I've made this fix on my code challenge and it still doesn't register the variable's contents in the output.

This is the code I've used.

<?php 
$name = "Mike";

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

</html>

Hi.

You forgot the ";" at the end of the php statement.

Try this: ... <?php echo $name; ?> ...

Dario

Give a man a fish he will be hungry tomorrow, teach him how to fish and he will never go hungry...

Sorry, when i posted solution your answer wasn't still visible on my browser. Our man will learn to fish next time.

Thanks for the response. I did make this fix on my code but it still isn't registering the output correctly. Take a look at the response that I gave Jeremy.

I also have a problem with this challenge, and I only write the code that should be necessary for completion:

<?php $name="Mike" ?>

<?php echo $name; ?>

But still, it doesn't register :/

Check the ";" in first instruction....

I make use of the ";" in the end of the php statement

<?php echo $name; ?>

but it still won't register a thing. What am I missing here?