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

PHP PHP Basics (Retired) PHP Data & Structure PHP Variables

Stuck on php basics exercise 2

I am on php basics exercise #2 learning about variable. There are two parts to this exercise. Part one consist of creating a php bracket with the variable "name" set to "mike", see below:

  1. <?php 2. 3.$name = "mike"; 4. 5.?>

The second part part ask us to echo mikes name to the screen. I understood this to mean outside of the php bracket and instead of using the word mike use the variable. So I was doing this:

<?php echo $name ?>

I keep getting bummer! I also tried using the example from lesson number one:

<?php echo "mike" ?>

still no good! I also did it inside the php bracket as well and nothing. What am I doing wrong?

3 Answers

For me, this worked:

<?php $name = "Mike"; ?>
<?php echo $name; ?>

but you can also do:


$name = "Mike";
echo $name;


It may be case sensitive - I notice you've used "mike" instead of "Mike". Also remember to add a semi-colon at the end of every statement, even if they're inside different php tags:

# no semi-colon
<?php $name = "Mike" ?>
<?php echo $name ?>

# with semi-colon
<?php $name = "Mike"; ?>
<?php echo $name; ?>

had no idea there were many options.

There's always lot's of ways to do things. The best way is always the method which requires the least code!

<?php 2. 3.$name = "mike"; 4. 5.?>

should be:

<?php $name = "mike"; ?>

I didn't mean the 4.5?> That was a typo. sorry for the confusion.

Jason Larkin
Jason Larkin
13,970 Points

I have been struggling with the second part of the challenge too.

<?php $name = "Mike"; ?> <?php echo $name; ?>

This is what I have and it's not working for me. Can anyone help please?