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 PHP Basics (Retired) PHP Data & Structure PHP Variables

alan heath
alan heath
5,188 Points

"mike" is not showing to screen

i believe i have the right syntax but it still does not show up.

index.php
<?php

$name = "Mike";

?>
<html>
  <head>
  <body>
<p><?php echo $name ?></P>
   </body>
  </head>

</html>

3 Answers

Samuel Webb
Samuel Webb
25,370 Points

Oh 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.

alan heath
alan heath
5,188 Points

Thank you Sam. That did the trick. I was over thinking it.

Samuel Webb
Samuel Webb
25,370 Points

Hi 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
alan heath
5,188 Points

In 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 ...

Hello 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
Samuel Webb
25,370 Points

I think you put code in here but it doesn't seem to be showing up.

It must have excaped it. And good job for noticing that semi-colon I somehow missed it.

Samuel Webb
Samuel Webb
25,370 Points

Yeah 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.