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 trialBenjamin Casalino
3,533 Pointsvery frustrated, not sure what I'm doing wrong? <?php $name ="Mike"?> <?php echo = "Mike"?>
PHP basics part 2, is asking to echo mikes name to the screen?
<?php $name ="Mike"?>
<?php echo = "Mike"?>
4 Answers
Patrizia Lutz
1,449 PointsYou can't assign a value to echo, which is a PHP function that outputs a string (or multiple strings).
You should declare the variable $name
and assign the value "Mike". Then use echo
to print it out.
<?php $name = "Mike"; ?>
<?php echo $name; ?>
or
<?php
$name = "Mike";
echo $name;
?>
You can also concatenate strings and variables like so:
<?php echo 'Hi, my name is ' . $name . '.'; ?>
//=> Hi, my name is Mike.
David Tonge
Courses Plus Student 45,640 PointsI moved your answer to answer so it could be selected as "best answer" I realized I was missing a semi-colon in my answer.
Jeff Lemay
14,268 PointsKEEP EVERYTHING IN A SINGLE PHP BLOCK! This question comes up often. There should really be an instruction added to the code challenge.
But you also have some other issues...
- When you combine the two statements into a single php block, you'll need to close each with a semi-colon (well, technically, you only need to close the first one where you set the name variable)
- You are not echoing the variable properly. You tried echoing just a string, but you don't use an equal sign for echoing variables/strings.
<?php
$name = "Mike";
echo $Mike;
?>
Benjamin Casalino
3,533 Pointsthank you for responding! this objective is driving me crazy haha, i get what your saying but unfortunately this didnt work in workspaces.
Jeff Lemay
14,268 PointsOops, it should be echo $name
David Tonge
Courses Plus Student 45,640 PointsYou almost had it. You created the variable some instead of typing "mike" every time you're able to just call on the variable.
<?php $name ="Mike";
echo $name; ?>
Benjamin Casalino
3,533 Pointsahhh thank you so much!!
David Tonge
Courses Plus Student 45,640 PointsIf you look at all the answers they're basically the same thing. I think it may be how you entered your answer.
Benjamin Casalino
3,533 PointsBenjamin Casalino
3,533 Points<?php $name = "Mike"; echo $name; ?>
out of all the answers that is the only one that worked. not sure if its an issues with workspaces or im still a noob? :) thanks everyone!