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

Cannot see result of PHP code in browser

I am watching the PHP Variables video and I have changed the html code to php variables where instructed. Where "Mike the Frog" used to be displayed during Preview, now there is nothing. Anything not PHP is displayed in the browser. What am I missing? Yes, I renamed index to a php file. I even have WAMP installed and online, but I really want to use Workspaces since I am on multiple devices throughout the day. I have scoured the code to try and find careless errors, but I am not seeing anything (doesn't mean it's not there.)

Here is my code for index.php

<? php

  $name = "Mike";
  $location = "Orlando, FL";
  $full_name = "Mike the Frog";
  $name = $full_name;
?>

<!DOCTYPE html>
<html>
  <head>
    <meta charset=utf-8>
    <title><?php echo $name ?>| Treehouse Profile</title>
    <link href="css/style.css" rel="stylesheet" />
  </head>

  <body>
    <section class="sidebar text-center">
      <div class="avatar">
        <img src="img/avatar.png" alt="<?php echo $name ?>">
      </div>
      <h1><?php echo $name ?></h1>
      <p><?php echo $location ?></p>
      <hr />
      <p>Welcome to PHP Basics!</p>
      <hr />
      <ul class="social">
        <li><a href=""><span class="icon twitter"></span></a></li>
      </ul>
    </section>
    <section class="main">
      <p>Let's Get Started!</p>
      <p><?php echo "Hello, World!"?></p>
    </section>
  </body>
</html>

If I didn't mark it up correctly, sorry, this is my first time asking a question. Thanks in advance.

2 Answers

Hello Amber,

Change

<? php

to

<?php

That's it. An easy mistake to make, I've done it plenty of times myself. (Still do on occasion)

Hope it helps!

Philip

Another thing I've learned about PHP, that's it really stubborn and unforgiving — unlike HTML + CSS. If your syntax isn't perfect — you'll get an error. Be eagle eyes and check for typos, it's easy to miss the little things.

You'll get the hang of it!

Thank you. I fixed it and now it works. It would be a glaring error in the first line, d'oh!