Hi this has been driving me nuts for days.
I have a form posting data to the script below and the part i have posted is validating the email and name fields.
I have played with it a bit and the function checkOK is always returning the value of the last if statement.
I have tried swaping the staments round and it is always the last one it returns the value from. has me stumpted.
Basical the function 1st check the name field is not empty if it is it returns a error code of 1 then it checks the email field and if the email does not match the regual expression or it is empty it returns and error code of 2 then it checks against both the user name and email address and if the are both wrong it returns an error code of 3. Im not entirly sure the syntax is correct any more as the function will always return the last value even if i swap around what each if statment is checking for.
PLEASE HELP
<?php
include ('config.php');
include ('global.php');
$ID = '';
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$phone2 = $_POST['phone 2'];
$street = $_POST['street'];
$city = $_POST['city'];
$country = $_POST['country'];
$createdate = date("Y-m-d");
$result = checkOK();
function checkOK(){
if ($name == null){
$errcode = '1';
}
if ((!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]",$email)) || ($email == null)){
$errcode = '2';
}
if (($name == null) && ((!eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]",$email)) || ($email == null))){
$errcode = '3';
}
else{
$errcode = null;
}
return($errcode);
}
if ($result != null){
header('Location: dashboard.php?p=addclient&success=no&error='. $result);
}


