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!
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

Andrew McCombs
4,309 PointsIf Statement Help - PHP
I don't understand how to run this the right way, what I want it if the first part of the if statement isnt trun then see if the second on is.
if (($user_ok === true && $log_username === $post_author) && ($user_ok === true && $log_userlevel === 7 && $log_userlevel === 8)){
echo $editPostbtn;
}
2 Answers

Timothy Rimnac
26,219 PointsI'm not exactly sure what you're asking but I'm assuming that you want to check if one OR the other condition is true. Using the '&&' means that both the first AND the second condition is true. You'll want to use the OR comparator also known in PHP as the double pipe, '||'.
Try running the code as
if (($user_ok === true && $log_username === $post_author) || ($user_ok === true && $log_userlevel === 7 && $log_userlevel === 8)){
echo $editPostbtn;
}
Notice that the '&&' between the two conditionals was replaced with '||', also known as the OR comparator.

Bill Hinostroza
19,273 PointsI don't know if this is what you're looking but it was worth giving it a try.
if ($user_ok === true && $log_username === $post_author){
echo $editPostbtn;
}
elseif($user_ok === true && $log_userlevel === 7 && $log_userlevel === 8)){
echo "Whatever";
}
else{
echo "Please input the correct information."
}