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

Melita Carty
Melita Carty
14,421 Points

Can't see where I'm going wrong, it says "Use the negation operator to check that $role is NOT EQUAL to "admin"."

I can't tell if my error is in a different part of the code or if I'm just not understanding the negation operator for the admin part.

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

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

2 Answers

Zachary Billingsley
Zachary Billingsley
6,187 Points

Hello!

As Mikkel said, you can use isset, but another way to pass this quiz is by just removing the negation operator from the first part of the conditional, so that ($username == "" || $role != "admin").

It's like saying in plain english -> "IF the $username is equal to nothing OR the $role of the user is NOT EQUAL to admin, don't show them the page"

Melita Carty
Melita Carty
14,421 Points

Hey! Thanks for the help. Strangely, after working with my original code, it seems that just adding spaces in the places where you put spaces made it work too (I thought whitespace didn't matter? Maybe it's something to do with how it marks my work...)

Zachary Billingsley
Zachary Billingsley
6,187 Points

You are very welcome!

Yes sometimes the code challenges can be a bit finicky... And while it is acceptable to not have whitespace between operators and variables, it is pretty common practice to see some spacing, mainly for readability.

Mikkel Rasmussen
Mikkel Rasmussen
31,772 Points

You need to check if username is set using the function isset($username) and not $username != ''