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 Switch Statements

why do i get that syntax error on line 16 ? (it is the end of the code "?>"

<?php //Available roles: admin, editor, author, subscriber if (!isset($role)) { $role = 'subscriber'; }

//change to switch statement if ($role != 'admin') { switch ($role) { case 'admin': echo "As an admin, you can add, edit, or delete any post."; break; default: echo "You do not have access to this page. Please contact your administrator."; }

?>

switch.php
<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
    $role = 'subscriber';
}

//change to switch statement
if ($role != 'admin') {
  switch ($role) { case 'admin': 
                  echo "As an admin, you can add, edit, or delete any post.";
                  break;
                   default: echo "You do not have access to this page. Please contact your administrator."; 
}

  ?> 

4 Answers

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Omer,

Try removing the if statement that surrounds the Switch statement you wrote. You need to use a Switch statement instead of the if condition. Good luck :)

not working !

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

I'm getting some problems at the moment with code challenges but the code should work if you remove the 2nd if statement because you're checking for a subscriber which reverts to the default case not the admin case.

<?php
//Available roles: admin, editor, author, subscriber
if (!isset($role)) {
    $role = 'subscriber';
}

//change to switch statement
 switch ($role) { case 'admin': 
                  echo "As an admin, you can add, edit, or delete any post.";
                  break;
                   default: echo "You do not have access to this page. Please contact your administrator."; 
}

you mean code challenges of tree house make the problem ?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

No it's just a server outage error. A common problem that the technical guys at Treehouse have probably already fixed. So, you may need to give it a few moments but try the above code and you should be able to get it to pass the challenge.

Remember what I talked about with removing the 2nd if statement? As I'm sure you'll know, the Switch statement is just another type of condition. What you need to do is get the default case output which you'll get because the value of $role is not admin. :-)

thanks i will try it !