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

Zeljko Kadic
Zeljko Kadic
855 Points

Hello, can someone explain to me why this code dosen't show? Thanks

<html>
<?php
$username = "Treehouse";
if ($username) {
    if ($username != "Treehouse") {
        echo "Hello $username";
    }
} else {
    echo "You must be logged in";
}
?>
</html>

1 Answer

-- --
-- --
12,382 Points

Hi Zeljko,

Next time, refer to the Markdown Cheatsheet to display your code in a more legible way. :)

You made an error in your if-statement. This is the correct way of writing what you would like the code to do (this displays "You must be logged in.", because != makes the statement false):

<?php

$username = "Treehouse";

if ($username != "Treehouse") {
    echo "Hello $username!";
  } else {
    echo "You must be logged in.";
  }

?>

To make the statement true, simply remove the ! from !=. In that case, "Hello Treehouse!" will be displayed.

Happy coding!