Validation code tips if (isset($_POST['submit'])) {
    if (isset($_SESSION['token']) &amp;&amp; $_POST['token'] == $_SESSION['token']) {
        $errors = array();
        $error = 0;

        if (!preg_match('/^[A-Za-z](?=[A-Za-z0-9_.]{3,20}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/i', $_POST['username'])) {
            $errors[] = 'Your username must start with a letter (A-Z) and be between 3-20 characters and may only contain alphanumeric characters (A-Z, 0-9 _ ) or a period (1) (".")';
            $error = 1;
        }

        $STH = $DBH-&gt;prepare("SELECT username FROM users WHERE username = ?");
        $STH-&gt;execute(array($_POST['username']));

        if ($STH-&gt;rowCount() &gt; 0) {
            $errors[] = 'The username is already taken!';
            $error = 1;
        }

        if (strlen($_POST['password']) &lt; 3) {
            $errors[] = 'Your password must be longer than 3 characters!';
            $error = 1;
        } else if ($_POST['password'] != $_POST['passconf']) {
            $errors[] = 'You didn\'t verify your password correctly!';
            $error = 1;
        }

        if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
           $errors[] = 'The e-mail is not valid!';
           $error = 1;
        } else {
            $STH = $DBH-&gt;prepare("SELECT email FROM users WHERE email = ?");
            $STH-&gt;execute(array($_POST['email']));

            if ($STH-&gt;rowCount() &gt; 0) {
                $errors[] = 'The email is already taken!';
                $error = 1;
            }
        }
    }
}


This is my current validation for a registration page it works, but I'd like to improve it, give me some tips
You have two long if blocks:

if (isset($_POST['submit'])) {
    if (isset($_SESSION['token']) &amp;&amp; $_POST['token'] == $_SESSION['token']) {
    ...
    }
}


Why not combine them?

if (isset($_POST['submit']) &amp;&amp; (isset($_SESSION['token']) &amp;&amp; $_POST['token'] == $_SESSION['token'])) {
    ...
}


also the way you've structured this, you don't need $error, to see if there are errors you can simply check empty($errors) (true => ok, false => not ok).

Other than that, your code looks fine.