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 trialalan heath
5,188 Points"mike" is not showing to screen
i believe i have the right syntax but it still does not show up.
<?php
$name = "Mike";
?>
<html>
<head>
<body>
<p><?php echo $name ?></P>
</body>
</head>
</html>
3 Answers
Samuel Webb
25,370 PointsOh sorry about that. I was just looking at your code and correcting what looked incorrect about it. I didn't actually look at the code challenge. You actually don't need all of that html that you put in there. Your code should look like this:
<?php
$name = 'Mike';
echo $name;
At the end of the file, make sure you DON'T close the PHP tag. You don't need to close the PHP tags when the file consists of only PHP. It helps prevent white space issues. Sorry for the confusion the first time around.
Samuel Webb
25,370 PointsHi Alan,
Like what was said above, you need to separate your body tag from your head tag because the head tag is not for page viewable tags. Your formatting should look like this:
<?php
$name = "Mike";
?>
<html>
<head>
</head>
<body>
<p><?php echo $name; ?></p>
</body>
</html>
Also, if you noticed, I added a semi-colon to the end of your statement. You always want to end all of your PHP statements with the semi-colon or it could cause problems in your project.
alan heath
5,188 PointsIn the example it does not show a semi colon in the echo statement but i tried it both ways and it still does not work
... index.php
1
<?php
2
3
$name = "MIke";
4
5
?>
6
<!DOCTYPE html>
7
<html>
8
9
10
<body>
11
<p><?php echo $name ?></p>
12
</body>
13
</html>
14 ...
Kristian Terziev
28,449 PointsHello Alan,
The mistake here is that you put your <body> tag inside the <head>. The main html structure is this:
<html> <head> </head> <body> </body> </html>
Nothing you put inside the head will be visible on the page.
Samuel Webb
25,370 PointsI think you put code in here but it doesn't seem to be showing up.
Kristian Terziev
28,449 PointsIt must have excaped it. And good job for noticing that semi-colon I somehow missed it.
Samuel Webb
25,370 PointsYeah in PHP semicolons are the bane of my existence. I've had to deal with so many semicolon issues that I now automatically look for them before I investigate any other problem.
alan heath
5,188 Pointsalan heath
5,188 PointsThank you Sam. That did the trick. I was over thinking it.