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

Michel Stroobants
Michel Stroobants
5,014 Points

Can't seem to find what I did wrong in the exercise?

title

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 administrator.";
}

4 Answers

Your 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.";
}
Michel Stroobants
Michel Stroobants
5,014 Points

I got it to work! It was just the spacing... I didn't know spacing would matter that greatly.

Hi, 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
Michel Stroobants
5,014 Points

Hi, 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".

Hi, ensure you add spaces when using conditionals.

Change from this

$role!='admin'

to

$role != 'admin'
Michel Stroobants
Michel Stroobants
5,014 Points

Still 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