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

concatenation php Code Challenge

Hey guys, I'm currently busy with the php challenge: http://teamtreehouse.com/library/programming/build-a-simple-php-application/adding-a-contact-form/concatentation

I don't know what I'm doing "wrong" and would really like to know that :-) Any ideas?

This is the task: Create a variable called fullName and assign it a value equal to the concatenation of the firstName variable, a space, the middleName variable, a space, and the lastName variable.

This is the error Message: Bummer! $fullName is set, but it's not the concatenation of $firstName, $middleName, and $lastName with spaces between them.

That's my code: <?php

$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName =""; $fullName = "$firstName " . "$middleName " . "$lastName ";

echo "The designer at Shirts 4 Mike shirts is named ____";

?>

9 Answers

James White
James White
6,159 Points

Almost. That concatenates the names but doesn't add the space. You have to add a " " in between the names.

$firstName . " " . $middleName . " " . $lastName;

Charmaine Wallace
Charmaine Wallace
22,276 Points

And one year later I found this. About to pull my eyeballs out in frustration, I discovered that I did not have an actual space between the quotation marks, hence it kept telling me that there was no space concatenated between the variables. o_0

James White
James White
6,159 Points

You don't need double quotes around your variables.

Make $firstName . " " . $middleName . " " . $lastName;

$fullName = $firstName ." ". $middleName ." ". $lastName;

kobi arami

hey James, thanks for for your reply. you mean like that? <?php

$firstName = "Mike"; $middleName = "the"; $lastName = "Frog"; $fullName =""; $fullName = $firstName . $middleName . $lastName ;

echo "The designer at Shirts 4 Mike shirts is named ____";

?>

All I can say is wow how did i miss that.

Sam Lozier
Sam Lozier
9,699 Points

Weird i've entered the proper code and when I hit preview, I get the desired output, but it won't check out. After reloading the page and re-starting the challenge, it works fine.

Charmaine Wallace
Charmaine Wallace
22,276 Points

That's happened to me Sam. Although most of the time not paying attention is to blame. HTML is very forgiving, PHP not so much!

Estevan Montoya
PLUS
Estevan Montoya
Courses Plus Student 23,989 Points

I had this:

$fullName = $firstname . " " . $middleName . " " . $lastName;

Does anyone see my mistake? It took me a while to figure out "name" was not capitalized in $first...