I have come to a stumbling block on my validation for a registration form, and wondered if you could kindly point me in the direction of the solution. Firstly here is my code;
<?php
$fname_x = $sname_x = $email_x = $password_x = $password_c = $capch_x = "txta";
if ($_POST)
{
$error = "";
if(empty($FNAME))
{
$error = "<b>Please enter a first name.</b><br/>";
echo"$error";
$fname_x ="error";
}
if(empty($SNAME))
{
$error = "<b>Please enter a surname.</b><br/>";
echo"$error";
$sname_x ="error";
}
if(empty($EMAIL))
{
$error = "<b>Please enter a email address.</b><br/>";
echo"$error";
$email_x ="error";
}
elseif(!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$',$EMAIL))
{
$error = "<b>Please enter a valid email address</b><br/>";
echo"$error";
$email_x ="error";
}
if(empty($PASSWORD))
{
$error = "<b>Please supply a password.</b><br/>";
echo"$error";
$password_x ="error";
}
elseif($PASSWORDC != $PASSWORD)
{
$error = "<b>Please ensure both passwords match.</b><br/>";
echo"$error";
$password_c ="error";
}
if(md5($_POST['security']) != $_SESSION['key'])
{
$error = "<b>Please enter the security code correctly</b>";
echo"$error";
$capch_x ="error";
}
}
?>
The Problem;
Everything seems to work fine up until the point all my corrections have been rectified, i.e. text in required fields, passwords match, but it skips the email validation. So for example if i miss a required field like name, but i have an incorrect email in the email field it will pick up email as invalid, but than when i input a name for example, it completly skips the email validation. This occurs on all fields where its just text, for example, forename, surname, password, if any of these fields are blank and email is formulated incorrectly it will say Hey, please enter text in required fields, and enter a correct email address, put once i input text in required fields, it submits the form completly skipping the email validation
Can someone please assist me of this matter!
Many thanks for help in advance!
Adambob