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 trialNoah Savage
1,512 PointsIs there an error on this page?
I don't see where the error is. Even after making the html segment there is no output on the preview.
<?php
$name = "Mike";
echo $name
?>
<?php echo $name ?>
<!DOCTYPE html>
<?php echo $name ?>
<html>
<head>
<meta charset=utf-8>
<title><?php echo $name ?></title>
<link href="css/style.css" rel="stylesheet" />
</head>
<body>
<h1><?php echo $name ?></h1>
<p><?php echo $name ?></p>
</body>
</html>
<?php echo $name ?>
3 Answers
David Tonge
Courses Plus Student 45,640 Pointsyou aren't closing your PHP statements. There should be a semi-colon after the $name variables.
Noah Savage
1,512 PointsI thought it might be that, but I thought single argument PHP statements don't require a semi-colon?
ALAS!! I tried it in Firefox and it worked fine. It turns out that something was buggy with my Chrome browser cache. Worked just fine in Chrome when I restarted it. Thank you for your help! :)
Chris Shaw
26,676 PointsHi Noah,
While you've said your issue is resolved I noticed you don't have a semi-colon after your $name
variables as mentioned by David Tonge , while you're correct in saying you don't need this after single line statements you are missing the semi-colon when you first create the $name
variable.
<?php
$name = "Mike";
echo $name; // <-- missing semi-colon here
?>
Happy coding!
Noah Savage
1,512 PointsDo you mean when I first called the $name variable with echo? I know it's not best practices, but the code will execute properly without a semi-colon following the last statement in a PHP segment. I do understand that carefully entering the correct syntax is paramount, considering that a missing semi-colon anywhere else would certainly serve up a blank/error page. My issue was merely a problem with the browser cache, or some other browser related issue. Someone else may come across the same problem I had. Even with the correct syntax, glitches happen; which is why I'm belaboring the point. Thank you both for your diligence. =)