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 trialArikaturika Tumojenko
8,897 PointsParse error: syntax error, unexpected end of file
I am getting this error "Parse error: syntax error, unexpected end of file" when I am trying to run my code and from what I read it means I didn't close something, somewhere and it doesn't necessarily refer to the line where PHP it's showing me the error.
I can't seem to find where the error is though. Can anyone spot it? Thank you! My complete code is:
$firstName = "Silvia";
$lastName = "Bogdan";
$currentGrade = 10;
$finalAverage = .99;
$messageBody = "";
if (!$firstName || !$lastName) {
echo "Please enter a student name";
} elseif ($currentGrade <9 || $currentGrade > 12) {
echo "This is only for high school students. Please enter a grade between 9 and 12.";
} else {
echo "Dear $firstName $lastName\n";
echo $messageBody;
if ($finalAverage < .70) {
$messageBody = "We look forward to seeing you at summer school, beginning July 1st!";
} else {
switch ($currentGrade) {
case 9:
$messageBody = "Congratulations on completing your freshman year in High School! We’ll see you on September 1st for the start of your sophomore year!";
break;
case 10:
$messageBody = "Congratulations on completing your sophomore year in High School! We’ll see you on September 1st for the start of your junior year!";
break;
case 11:
$messageBody = "Congratulations on completing your junior year in High School! We’ll see you on September 1st for the start of your senior year!";
break;
case 12:
$messageBody = "Congratulations! You’ve graduated High School! Don’t forget to come back and visit.";
break;
default:
$messageBody = "Error: Grade level is not 9-12!";
break;
}
}
?>
```php
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! The reason you're receiving an end of file is because you're missing a closing curly brace before the ?>
. There should be 3 there. That being said, when you fix that, you'll notice that the $messagebody is not being echoed out. This is because you're echoing the message body when it's still an empty string. To display it, you'll need to echo the $messagebody after you've changed it from an empty string.
Hope this helps!