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 trialAnthony Harrison
1,064 PointsEcho variable
Where am I going wrong?
<?php
$name = "Mike"
?>
<html>
<body>
<h1><?php echo $name ?></h1>
</body>
</html>
7 Answers
Matt Trask
10,027 Pointsyoure missing a semi colon. I dont wanna give it up, but remember, most lines of PHP will always end with a semi colon.
Anthony Harrison
1,064 PointsBummer! I am not seeing the word "Mike" in the output. Did you echo something different?
This is all I get trying to print Mike on the screen, after adding semi colon to the end of the first code block after the "mike"
Matt Trask
10,027 Points<?php
$name = "Mike"; <- semi colon here
?>
<html>
<body>
<h1><?php echo $name;(since you close out the PHP block, you can forgo a semi colon, but for good practice I added it) ?></h1>
</body>
</html>
thomascawthorn
22,986 PointsI didn't know this was best practice, have you got a reference by any chance :-)
Matt Trask
10,027 PointsIve seen it before Tom Cawthorn, but lemme look to find it. I think its apart of the PSR's
Anthony Harrison
1,064 Points<?php
$name = "Mike";
?>
<html>
<body>
<p><?php echo $name?></p>
</body>
</html>
This is what I have, its still showing the same message. Im stumped.
Matt Trask
10,027 Pointsadd a semi colon after the echo statement in the html body.
Steven McKay Lowry
2,015 PointsCould try:
<?php
$name = "Mike";
echo '<html>';
echo '<body>';
echo '<p>';
echo $name
echo '?';
echo '</p>';
echo '</body>';
echo '</html>';
?>
I think it might be because the variable you're trying to choose is between two different PHP segments. (Not global)
thomascawthorn
22,986 PointsYour code looks totally fine - are you struggling passing a challenge or is this in your own local environment?
Anthony Harrison
1,064 PointsIt was the code challgne, I have passed it now. The echo php had to be done outside of html elements
thomascawthorn
22,986 PointsCode challenges are very picky! If your feel it wasn't explained properly in the question, you can always send in an email to the support team, or leave feedback at the end of the badge to get it updated.
Glad you got it through!