How to validate email and name separately in PHP script

Hello everybody,

I have this PHP script and as you can see I’m telling the script to check whether the email and the name comply with the validation rules and if so insert the data coming from a Flash registration form. My question is, how do I check for both the email and name separately?. Sorry, I’m a bit new to this…


$conexion=@mysql_connect(localhost,root,"Mckako01" ) or die (mysql_error());
$select=@mysql_select_db("formulario");
//reglas para validar nombre, email

$valNombre='/^[a-z]{3,}$/i';
$valEmail='/^\w[-.\w]*@([-a-z0-9]+\.)+[a-z]{2,4}$/i';

//variables
$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$direccion=$_POST['direccion'];
$email=$_POST['email'];
$fuente=$_POST['fuente'];
$comentarios=$_POST['comentarios'];
$noticias=$_POST['noticias'];
//insert data only if validation rule is ok
if(preg_match($valNombre,$nombre) && preg_match($valEmail,$email) ){
$insertar="INSERT INTO datos (nombre,apellido,direccion,email,fuente,comentario s,noticias) VALUES ('$nombre','$apellido','$direccion','$email','$fue nte','$comentarios','$noticias')";
$consulta=@mysql_query($insertar);
echo "&exito=true";
}else{
echo "&exito=false";
}

Million thanks,

Maria