Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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:

<?php

$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?