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 trialZachary French
1,081 PointsI wrote the conditional statement. It shows it working properly in the preview, but says incorrect. Not sure why.
The two requirements for the statement: That a $username is set. The users $role is NOT admin
my conditional state
if ($username && $role != 'admin'){ ..... }
As far as I can tell, it should work and satisfy both requirements.
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';
if (($username) && $role !='admin') {
//add conditional statement
echo "You do not have access to this page. Please contact your administratior.";
}
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Zachary,
This challenge seems to require a specific format on the code.
I added a space after !=
and it passed.
So nothing wrong with your code.
The challenge doesn't require it but a better way to check if the variable is set is to use the issset()
function.
isset($username)