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 trialAsif Ulfat
8,616 PointsWithout changing the variables, create a SINGLE conditional statement around the echo command that checks
need help
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';
//add conditional statement
if($role!="admin" ){
echo "You do not have access to this page. Please contact your administrator.";
}
1 Answer
Felipe Giovanni de Moura Santos
23,702 PointsWhat's up man... Let's go:
We want to know IF the $username is set AND IF the value of the variable $role is not 'admin', all of that in one single conditional statement. What we'll use
1 - PHP's built-in function isset() //checks if a variable is set and is not NULL.
2 - && (AND).
3 - != (not equal).
<?php
$username = 'sketchings';
//Available roles: author, editor, admin
$role = 'editor';
if( isset($username) && $role != 'admin'){
echo "You do not have access to this page. Please contact your administrator.";
}
?>