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
Cesar Gonzalez
17,443 PointsHaving 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
Dario Morbidi
33,072 PointsIn 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.
Jeremy Germenis
29,854 PointsYour echo $name is missing something... (wink)
Cesar Gonzalez
17,443 PointsOne 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>
Dario Morbidi
33,072 PointsHi.
You forgot the ";" at the end of the php statement.
Try this: ... <?php echo $name; ?> ...
Dario
Jeremy Germenis
29,854 PointsGive a man a fish he will be hungry tomorrow, teach him how to fish and he will never go hungry...
Dario Morbidi
33,072 PointsSorry, when i posted solution your answer wasn't still visible on my browser. Our man will learn to fish next time.
Cesar Gonzalez
17,443 PointsThanks 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.
Richard Stålnacke Larsson
6,977 PointsI 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 :/
Dario Morbidi
33,072 PointsCheck the ";" in first instruction....
Richard Stålnacke Larsson
6,977 PointsI 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?
Cesar Gonzalez
17,443 PointsCesar Gonzalez
17,443 PointsThat worked out. I suppose I was jumping ahead of myself. Thank you very much for your help.