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 Basics (Retired) PHP Conditionals & Loops If / ElseIf Conditionals

shane smales
shane smales
1,933 Points

why wont it accept my if statements

as soon as i input if statments it wont display the preview page in workspace on port 80

here is my code:

<?php

define("USE_FULL_NAME", FALSE); define("MAX_BADGES", 150000);

$first_name = "Hampton"; $last_name = "Paulk"; $location = "Orlando, FL"; $role = "Teacher";

if( USE_FULL_NAME == TRUE){ Β£name = $first_name.' '.$last_name; }else{ $name = $first_name; }

if( $role == 'Teacher' ){ $info = "I am a Teacher at Treehouse."; }

?>

6 Answers

Hi shane,

This is funny, to me anyhow. In the States we don't have a key for the British Pound, we only have the dollar sign ($). Look in the first if statement.

Jeff

Bill Hinostroza
Bill Hinostroza
19,273 Points

The reason your code is failing is because your constant "USE_FULL_NAME" is false. Your first if statement is checking if that constant is equal to true but it isn't. That's why your code isn't passing.

if( USE_FULL_NAME == TRUE)
shane smales
shane smales
1,933 Points

haha its right next to the dollar sign on my mac, my mistake all though it still wont run. for some reason it wont run any loops or if statements.

What is it supposed to do? There is no code to output anything. Before I fixed the variable the page wouldn't load, after the page loads but of course there is no output.

shane smales
shane smales
1,933 Points

Its suppose to alter the side bar in the PHP basics tutorial.

I managed to complete the tutorial without getting the code to work

thanks for all your help though especially with the $ sign haha

<?php

define("USE_FULL_NAME", FALSE); define("MAX_BADGES", 150000);

$first_name = "Hampton"; 
$last_name = "Paulk"; 
$location = "Orlando, FL"; 
$role = "Teacher";

if( USE_FULL_NAME == TRUE) { 
     $name = $first_name. '  ' .$last_name; 
   }else { 
     $name = $first_name; 
  }

 if ( $role == 'Teacher' ) { 
   $info = "I am a Teacher at Treehouse."; 
} else {
  $info = "I am not a Teacher at Treehouse";
}

?>

Shane, what you are missing is the statement to echo the $info variable in the sidebar.

<section class="sidebar text-center">
      <div class="avatar">
        <img src="img/avatar.png" alt="Mike The Frog">
      </div>
      <h1><?php echo $name; ?></h1>
      <p><?php echo $location; ?></p>
      <hr />
      <p><?php echo $info; ?></p>
      <hr />
      <ul class="social">
        <li><a href=""><span class="icon twitter"></span></a></li>
      </ul>
    </section>

For the page to display USE_FULL_NAME to be set to TRUE.

define("USE_FULL_NAME", TRUE);

Likewise if your variable $role is not equal to "Teacher" it will display "I am not a Teacher at Treehouse."