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 varables quiz not passing

Whats wrong with the code below? Its not passing part 2 of variables quiz.

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

Thanks.

4 Answers

The answer is in the notice of the challenge :). Don't forget...

The notice says "Bummer! Make sure you're echoing the variable you just set in the last step." Here is my code: <?php $name = "Shirts 4 Mike"; echo name; ?> What am I missing? Shouldn't "echo name;" work?

Did you try something else? I quite understand what you were trying to do, but do you undertand every word of code you are writing?

<?php  // here you have your opening tag for php, who says to the server "hey, I am a php request!"
   $name = "Shirt 4 Mike"; // you declare your variable with a $, saying to the server "this is a variable", and you give a value with " ", saying to the server "this is a string chain". ";" is saying the server "end of the action.
echo // you say the server "display what follow me on the screen"
name; // What do you say to the server here? What does it understand? What is name?
?> Here you close your php tag, saying to your server "ok now, bye"

Nevermind, I got it. It worked by echoing the "Shirts 4 Mike" instead of echoing the name variable.

You should be echoing the variable though. Defining a variable and then echoing the value rather than the variable itself defeats the purpose of creating the variable.

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