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 Data & Structure PHP Variables

<?php $name = "Mike"; echo "$name"; ?> The online interpreter won't accept this. Help

What is going on?

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

4 Answers

Tony Nguyen
Tony Nguyen
24,934 Points

Hey Jairo,

Your putting in the string:

echo "$name";

This is not correct since your output will be a string instead of the variable that contains the value of the name "Mike". You will need to get rid of your quotes like so:

echo $name;

Hey man thanks, I've tried that as well. What else could it be?

Tony Nguyen
Tony Nguyen
24,934 Points

Make sure that your entire code looks like this:

<?php
$name = "Mike";
echo $name;
?>
Abe Layee
Abe Layee
8,378 Points

By adding quotation mark around the the var name, it becomes a string.

<?php 
$name = "Mike";
echo "$name"; // this is a string
echo $name; //correct way
?>
jason chan
jason chan
31,009 Points

you don't need quotes in variables you already defined it.

quotes are only for strings.

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

If that does not work, I recommend that you refresh the browser and start the code challenge over again.