Redundant email checking in PHP This essentially checks if any of these if statements are true, then echos a statement.

Unfortunately, wrapping the error message with a div tag is impossible since I set error to 1 after I would have the div tag show up. I assume I could use a function for this but I don't understand how they work.

Is there a better way to check all these parameters then return a string that I can check if something exists in that string or not to post?

if ($error == '1'){ echo '&lt;div class="error_message"&gt;';}
if(strlen($display)&lt;4)
{
echo "Display name is too short. &lt;br&gt;";
$error = '1';
}
if ($email == '')
{
echo "You did not put a valid email adress. We require this to verify your account. &lt;br&gt;";
$error = '1';
}   
if(mysql_num_rows($check_display) != 0)
{
echo "Display name is already in use. &lt;br&gt;";
$error = '1';
}

if(mysql_num_rows($check_user) != 0)
{
echo "Username is already in use. &lt;br&gt;";
$error = '1';
}

if(mysql_num_rows($check_mail) != 0)
{
echo "Email is already in use. &lt;br&gt;";
$error = '1';
}

if ($pass != $pass2) 
{ 
echo 'Passwords do not match. &lt;br&gt;' ;  
$error = '1';
}
if ($error == '1'){ echo '&lt;/div&gt;';}
Like so:
Here you can see that is easier to have errors as an array, use alternative control statments to separate php from html:

 &lt;?php
    $messages = array();
    if(strlen($display)&lt;4)
    {
        $messages[] = 'Display name is too short';
    }
    if (empty($email))
    {
        $messages[] ='You did not put a valid email address. We require this to verify your account.';
    }   
    if(mysql_num_rows($check_display) != 0)
    {
        $messages[] = 'Display name is already in use';
    }

    if(mysql_num_rows($check_user) != 0)
    {
        $messages[] = 'Username is already in use.';
    }

    if(mysql_num_rows($check_mail) != 0)
    {
        $messages[] = 'Email is already in use.';
    }

    if ($pass != $pass2) 
    { 
        echo 'Passwords do not match.';  
    }
    ?&gt;
    &lt;div class="error_message"&gt;
        &lt;?php if(!empty($messages):?&gt;
            &lt;ol&gt;
            &lt;?php foreach($messages as $message):?&gt;
                &lt;li&gt;&lt;?php echo $message;?&gt;&lt;/li&gt;
            &lt;?php endforeach;?&gt;
            &lt;/ol&gt;
        &lt;?php endif;?&gt;
    &lt;/div&gt;