Hi there,
I am trying to verify if an email address that has been entered is valid. However, it won't accept a valid email address and I have been trying to find the error for the past two days, but I am unable to do so.
<?php
session_start();
//checks if the form has been submitted
if (isset($POST['submitted'])) {
$errors=array();
//checks whether a name has been enetered
if (empty($POST['nameField'])) {
$errors[]='Field 1 is empty';
} else {
$name=$POST['nameField'];
}
//checks whether an email address has been entered
if (empty($POST['Email'])) {
$errors[]='Answer Not selected';
} else {
$emailArray=stripslashes(trim($POST['Email']));
echo $emailArray;
//checks if the email entered is invalid
if (!eregi("[a-zA-Z0-9]*@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$]", $emailArray)) {
$errors[]='Please enter a valid Email address';
}
}
//writes the values into the session if the errors array was empty
if (empty($errors)) {
$_SESSION['Email']=$emailArray;
$_SESSION['nameField']=$name;//assigns the $name variable to the session array
$url='http://stuweb.cms.gre.ac.uk'.dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1)=='/') or (substr($url,-1)=='\\')) {
$url=substr($url,0,-1);
}
if (isset($_POST['previous'])) {
$url .= '/terms.php';
} else {
$url .= '/age.php'; /*doesn't test whether the input next g=has come from the mouse or keyboard*/
}
header("Location: $url");
exit();
}
}
I would be really grateful if somebody could point me in the right direction.
Thanks,
Sofia😕