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 Simple PHP Application Adding a Contact Form Working with Concatenation and Whitespace

Problem with concatenation returning 0's instead of entered text in Contact Form lesson of PHP.

Everything was working fine until I added Name:, Email: and Message: labels before variables. Now returning 0's. Any ideas whats wrong.

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

echo "Name: " + $name;
echo "Email: " + $email;
echo "Message: " + $message;
?>

2 Answers

Andrew Shook
Andrew Shook
31,709 Points

The problem is you are using the wrong operator (symbol) to concatenate. In PHP you use a period to concatenate things together and not a plus sign. Your code should look like this:

<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];

echo "Name:  " . $name;
echo "Email:  " . $email;
echo "Message:  " . $message;
?>

Thanks Andrew!!

Thanks Andrew!!