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 Operators

oliverchou
oliverchou
20,886 Points

Unexpected '!'

How to fix it, is there anything wrong with my syntax?

index.php
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';

//add conditional statement
if !(isset($username) && ($role=='author' || $role=='editor' || $role=='admin')) {
echo "You do not have access to this page. Please contact your administratior.";
}
?>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey there,

I feel you may have misunderstood what the challenge is asking for. It only wants two things: 1. To see if the $username variable is set and to check the $role variable and see that it's not "admin."

Right now, the conditional is negating everything and is checking for any and all user roles.

The conditional should only have two checks.

Below is the corrected code for you to review. I hope it'll make sense. If you're still not completely sure why the above code is incorrect, please review the previous video, because conditional checks play a very important role in the course.

Keep coding! :)

if ($username && ($role != 'admin')) {
  echo "You do not have access to this page. Please contact your administratior.";
}

:dizzy:

Jay Padzensky
Jay Padzensky
4,731 Points

Sorry for any/all the email notifications, Jason Anders. I'm attempting to replicate a bug here :)

It may be the ! Before the (isset ) not sure tho haven't really worked much with php