the best approach to giving an error message when validating
<p>I am a new programmer and am attempting to do some validation for a basic registration form. I have built a basic registration form that sends the user back to the same page when submitted. I have also created a user class and have created some basic validation functions. However, the functions have the error messages built into them. I obviously put the functions on the top of the registration form so when there is an error the errors are posted on the registration form. However, I have no control on how the error messages look and would like to know if there is a lot better way to somehow echo the error messages from outside the class so I can use some type of css or something else for better control of how they look. I hope that makes sense. Also when there is an error the user is sent back to an empty registration form. I was trying to figure out how to keep the valid information in the text boxes and just make them redo the invalid information. Here is a basic example of a validation I have done. I know its basic but I am very new to programming</p>

<pre><code>function validate_password($password)
{   
    $valid = TRUE;
    if ($password == '')
    {
        echo "&lt;p&gt; Please enter a value for the password &lt;/p&gt;";
            $valid = FALSE;
    }
    elseif($_POST['pwd'] !== $_POST['pwd2'])
        {
            echo "The passwords do not match please try again";
            $valid = FALSE;
        }
return $valid;
}
</code></pre>
