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 trialMichel Stroobants
5,014 PointsCan't seem to find what I did wrong in the exercise?
title
<?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 administrator.";
}
4 Answers
Evans Owino
24,888 PointsYour first solution was closer to the answer.
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';
if(isset($username) && $role != 'admin') {
//add conditional statement
echo "You do not have access to this page. Please contact your administrator.";
}
Evans Owino
24,888 PointsHi, you're almost there. Step one asks you to check "That a $username is set.", this is a clue that you should consider using the isset function (http://php.net/manual/en/function.isset.php).
Michel Stroobants
5,014 PointsHi, thanks for the feedback. I already tried solving it with isset($username) but this doesn't seem to fix the problem. If i try to check the exercise I get feedback saying: Use the negation operator to check that $role is NOT EQUAL to "admin".
Evans Owino
24,888 PointsHi, ensure you add spaces when using conditionals.
Change from this
$role!='admin'
to
$role != 'admin'
Michel Stroobants
5,014 PointsStill no fix :(, maybe there's an error in the exercise itself?
<?php $username = 'sketchings'; //Available roles: author, editor, admin $role = 'editor';
//add conditional statement if(isset($username) && ($role != ('admin'))){ echo "You do not have access to this page. Please contact your administrator."; }
gives the same outcome
Michel Stroobants
5,014 PointsMichel Stroobants
5,014 PointsI got it to work! It was just the spacing... I didn't know spacing would matter that greatly.