I am currently creating a registration page and checking for errors. I have the errors working correctly but when I report them, they end up on a new page. I was wondering how I get it to not redirect to a different page?
I echo out a div that I was thinking would appear next to the form but that is not occuring. Here is my form and error validation:
<form action="signup.php" method="post">
<input type="text" name="First_name" placeholder="First Name" />
<input type="text" name="Last_name" placeholder="Last Name" />
<input type="text" name="Email" placeholder="Email Address" />
<input type="text" name="Email2" placeholder="Comfirm Email Address" />
<input type="password" name="Password" placeholder="Password" />
<input type="submit" value="Submit" name="submit"/>
</form>
This is part of my php file.
if (isset($_POST['submit'])) {
$error = array();
$firstname=$_POST['First_name'];
$lastname=$_POST['Last_name'];
$email=$_POST['Email'];
$email2=$_POST['Email2'];
$password=$_POST['Password'];
if (strlen($password) <= 6 and strlen($password) >= 1) {
if (strlen($password) >= 20) {
if (strlen($email) >= 1 and strlen($email) <= 55) {
if ($email == $email2) {
if (ereg('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)) {
$sql = "INSERT INTO Users (First_Name, Last_Name, Email, Password) VALUES ('$firstname','$lastname','$email','$password')";
echo "Regiration Complete. Check Email for Validation.";
exit;
} else {
$error[] = 'Email is wrong';
}
} else {
$error[] = 'Email addresses are not the same';
}
} else {
$error[] = 'Email Address is too long';
}
} else {
$error[] = 'Password is too long';
}
} else {
$error[] = 'Password must be 6 Characters';
}
}
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values) {
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';