Any idea why this wont print the errors?
// Validate the email
if (preg_match($regex, $email))
$errors[] = "Invalid email address";
// ... and the password
if (strlen($password) < 4)
$errors[] = "Password is too short";
// No errors?
if (empty($errors))
{
// insert into db
}
// If there were any errors, show them
if (!empty($errors))
{
$errors = array();
foreach ($errors as $error)
echo '<li>'.$error.'</li>';
}
you are overwriting the array before output.
remove
$errors = array()and it should work.It would be cleaner by the way to initialize
$errors = array()in the very beginning of the script, and then check forcount($errors) > 0instead ofempty:that way, you will avoid notices about
$errornot being set.