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 Enhancing a Simple PHP Application Integrating Validation Errors Setting an Error Message Variable

I am having problems with the $error_message variable. Is it an in-build php variable or not? I cant figure that out

Anyone help... i want to understand the $error_message variable

1 Answer

Jeff Lemay
Jeff Lemay
14,266 Points

You set the variable yourself, it is not pre-built into php. You might set it to equal nothing at first and then, as you run through your validation, append text to it depending on what failed.

<?php
$error_message = "";
if (!isset($email)) {
   $error_message = "Your email address is required.";
}
?>

Thanx for the prompt response that worked after i assigned an empty value.. Referencing tothe task "setting up an error message variable". I tried putting the code below after the if($_SERVER(REQUEST_METHOD) statement:

if(isset($error_message)){ echo $error_message; }

On my preview the results still didnt show as randy's. I was forwarded to the white page with the error message inside the $error_message variable. is there some css styling i missed or somewhere i went wrong