Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Adding a Contact Form Working with Get Variables

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Why did you equal the

Why equal the variable $email_body to itself?

What is the difference of this:

$email_body = $email_body . "Name: " . $name . "\n"; $email_body = $email_body . "Email: " . $email . "\n"; $email_body = $email_body . "Message: " . $message; echo $email_body;

AND

This:

$email_body = "Name: " . $name . "\n"; $email_body = "Email: " . $email . "\n"; $email_body = "Message: " . $message;

Thanks

4 Answers

Ron McCranie
Ron McCranie
7,836 Points

This method is used so you can expand on the existing variable name. It's called concatenation. Every time you use an existing variable followed by a dot (.) your appending that data to then end of it. It could get confusing if you create a new variable name every time you just need to add a little more to an existing variable. Plus, in this example you want to start a new line every time you have a new line break \n

Shawn Flanigan
PLUS
Shawn Flanigan
Courses Plus Student 15,803 Points

In the first instance, you're concatenating information onto the original variable...adding strings to the end...effectively building up the email piece by piece. In the second example, you're simply overwriting the $email_body variable over and over again, so you end up with just the Message bits.

Abdulla Alshubbar
Abdulla Alshubbar
31,298 Points

Because you want to build on the previous code with some new code. Otherwise you will override it (i.e. the old code will disappear and only the new one will be there).

Giovanni Valdenegro
Giovanni Valdenegro
13,871 Points

Thank you guys makes perfect sense now.