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 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!!