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

nicholasgryczewski
nicholasgryczewski
2,919 Points

Without changing the variables, create a SINGLE conditional statement around the echo command that checks

Without changing the variables, create a SINGLE conditional statement around the echo command that checks: 1.That a $username is set. 2.The users $role is NOT admin

(note: I was given this isset($username) idea from a past question I posted of the same problem. It doesn't work for this challenge though. I haven't went over isset in my labs at all so maybe they want me to do it another way?)

index.php
<?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.";
}

1 Answer

andren
andren
28,558 Points

isset is not the only way to accomplish this task but it works fine, that is not the issue. The issue is that you have changed the contents of the string that gets echoed. Changing any part of the code you were not asked to change will usually lead to issue due to the code checker becoming confused.

You changed the word administratior to administrator. While I realize the first spelling is clearly a typo, that doesn't change the fact that changing it breaks the challenge. So you'll have to change it back.

If you change it back like this:

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

Then the code will work.