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 trialMelita Carty
14,421 PointsCan'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.
<?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
6,187 PointsHello!
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"
Mikkel Rasmussen
31,772 PointsYou need to check if username is set using the function isset($username) and not $username != ''
Melita Carty
14,421 PointsMelita Carty
14,421 PointsHey! 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
6,187 PointsZachary Billingsley
6,187 PointsYou 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.