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 Arrays and Control Structures PHP Conditionals School's Out

no matter what it display me the same massage

i put this code below and it always display me that massage : "please enter a student name"

regards omer

this is the code :

<?php


$firstname ='omer ';
$lastname ='cohen ' ;
$currentgrade=9;
$finalaverage=80;
$massagebody=' ' ;
if($firstname||!$lastname){  
echo 'please enter a student name';
}
elseif ($currentgrade<9||$currentgrade>12){
  echo 'this is for only high school student.
  please enter grade between 9 and 12 ';
}
else{
  if($finalaverge<.70){
    $massagebody='We look forward to seeing you at summer school, beginning July 1st! ';
  }
  else{ 
       switch ($currentgrade){
         case 9:
         $massagebody='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:
         $massagebody='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:
         $massagebody='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:
         $massagebody='Congratulations! You’ve graduated High School! Don’t forget to come back and visit. ';
         break;
         default:
         $massagebody='error:grade level is not 9-12';
         break;




       }

  }
  echo "dear $firstname $lastname\n";
  echo $massagebody;
  }







?>

Moderator edited: Added markdown to properly render the code on the forums.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Omer! I added some markdown to your code so that it will properly display here on the forums. Check out the Markdown Cheatsheet at the bottom of the "Add an Answer" section. It contains some great instructions on how to format your questions and answers for the forums! :sparkles:

5 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again, Omer! To answer your question, yes, given your current code, it will always display that message. And here's the block of code that's doing it:

if($firstname||!$lastname){  // If firstname is NOT empty OR lastname is empty
echo 'please enter a student name';
}

What it should be asking is if either the first name is empty or the last name is empty, please fill out the student's name:

if(!$firstname||!$lastname){  //If firstname is empty OR lastname is empty. ... you forgot a ! in this line
echo 'please enter a student name';
}

If you make that correction, you should see the message disappear.

Hope this helps! :sparkles:

thanks jeniffer but it still have this notice from console this one : PHP Notice: Undefined variable: finalaverge in /home/treehouse/workspace/school.php on line 35

Notice: Undefined variable: finalaverge in /home /treehouse/workspace/school.php on line 35
dear omer cohen
We look forward to seeing you at summer school, beginning July 1st!

this is the code :(there is an error on line 35 )

$firstname ='omer ';
$lastname ='cohen ' ;
$currentgrade=9;
$finalaverage=80;
$massagebody=' ' ;
if(!$firstname ||!$lastname){  
echo 'please enter a student name';
}
elseif ($currentgrade<9||$currentgrade>12){
  echo 'this is for only high school student.
  please enter grade between 9 and 12 ';
}
else{
  if($finalaverge<.70){
    $massagebody='We look forward to seeing you at summer school, beginning July 1st! ';
  }
  else{ 
       switch ($currentgrade){
         case 9:
         $massagebody='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:
         $massagebody='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:
         $massagebody='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:
         $massagebody='Congratulations! You’ve graduated High School! Don’t forget to come back and visit. ';
         break;
         default:
         $massagebody='error:grade level is not 9-12';
         break;




       }

  }
  echo "dear $firstname $lastname\n";
  echo $massagebody;
  }







?>

Moderator edited: Markdown added to code to render properly on the forums.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi again, Omer! The error you're receiving now is about an undefined variable. And this is because you've made a typo.

In your original declaration of the variable you typed this:

$finalaverage=80;

But when you try to use that variable again in a condition, there's a misspelling. Here's your code:

if($finalaverge<.70){

That should be:

if($finalaverage<.70){  //note the additional 'a' between the 'r' and 'g'

Hope this helps! :sparkles:

thank you princess .

jennifer can you help me with that post i wrote here : https://teamtreehouse.com/community/switch-if-statement-to-switch-statement

on bottom of the page .

regards omer

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

If you would like an answer to that, it would be better to post it as an entirely new question. This has a few benefits. It helps others see that you have a new pending question and helps keep the forums organized. Also, that question was originally posted 8 months ago and challenges are changed and updated frequently. The code that passed that challenge yesterday might not pass today. Make sure you link the challenge in your new question! :sparkles:

thanks jennifer here is the post :https://teamtreehouse.com/community/why-do-i-get-that-syntax-error-on-line-16-it-is-the-end-of-the-code someone has reply i did what he say and it does not work . can you write it for me ?

regards omer