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 Build a Basic PHP Website (2018) Adding a Basic Form Concatenation

Marcuz Gabriel Larsen
seal-mask
PLUS
.a{fill-rule:evenodd;}techdegree seal-36
Marcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 Points

Create a variable called $fullName and assign it a value equal to the concatenation of the $title variable, a space, the

What have I done wrong???

index.php
<?php

$title = "Dr.";
$firstName = "David";
$lastName = "Bowman";

$fullName = "Dr. " . $title . "David " . $firstName . "Bowman" . $lastName; 


echo "The lead character from 2001: A Space Odyssey is named ____";

?>
David Bath
David Bath
25,940 Points

I think if you echo out $fullName you will see what you are doing wrong. You are actually concatenating each variable to its text equivalent, so "Dr. Dr." etc. You just need to concatenate the variables (with added spaces).

Marcuz Gabriel Larsen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Marcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 Points

Thank you David for a quick reply! Unfortunately still a challenge!


<?php

$title = "Dr."; $firstName = "David"; $lastName = "Bowman";

$fullName = "$title " . "$firstName " . "$lastName "; echo $fullName;

echo "The lead character from 2001: A Space Odyssey is named ____";

?>


The preview shows correct but I get the message:

Bummer! Make sure $fullName is set to the concatenation of $title, $firstName, and $lastName, with spaces in between.

2 Answers

Carlos Federico Puebla Larregle
Carlos Federico Puebla Larregle
21,073 Points

You could solve the task like this:

<?php

$title = "Dr.";
$firstName = "David";
$lastName = "Bowman";

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

echo "The lead character from 2001: A Space Odyssey is named ____";

?>

We are assigning the variable $title a white space (" "), the variable $firstName another white space (" ") and finally the variable $lastName. All that using . (dots) to concatenate. I hope that helps a little bit.

Marcuz Gabriel Larsen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Marcuz Gabriel Larsen
Full Stack JavaScript Techdegree Graduate 16,462 Points

That worked thank you Carlos.

For the one who has the same challenge remember not to add a space after $lastName - even though it looks weird and is connected to the echo without a space: "Dr. David BowmanThe lead character from 2001: A space Odyssey is Named ___";

David Bath
David Bath
25,940 Points

When you use variables, don't put them inside quotes. Take a look at how Carlos did it.