all groups > flash data integration > february 2006 >
You're in the

flash data integration

group:

Validation rule in PHP doesn't seem to be working


Validation rule in PHP doesn't seem to be working txusm
2/4/2006 5:11:47 PM
flash data integration:
Hello everybody:

I have a registration form in Flash that sends the data to a PHP file which in
turn sends it to a database. The problem is that I have two validation rules
for the name (can't be less than 3 characters) and the email (x@x.x). When I
insert the data the PHP file has to check if the rules are complied with and
returns a variable (true or false) to Flash in order to display a success or
failure message . The thing is that no matter what I do I always get the
failure message and the data is not sent to the db. Please have a look at both
the PHP and ActionScript code below and let me know what I'm doing wrong with
the rules or maybe it's something else I can't figure out cause I will have to
repaint the wall in my room if I don't stop banging my head against it...

PHP:

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

$valNombre='/^{3,}$/i';
$valEmail='/^\w*@(+\.)+{2,4}$/i';

//recibir variables
$nombre=$_POST;
$apellido=$_POST;
$direccion=$_POST;
$email=$_POST;
$fuente=$_POST;
$comentarios=$_POST;
$noticias=$_POST;
//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,comentarios,noticias) VALUES
('$nombre','$apellido','$direccion','$email','$fuente','$comentarios','$noticias
')";
$consulta=@mysql_query($insertar);
echo "&exito=true";
}else{
echo "&exito=false";
}


?>

ActionScript:

var enviar:LoadVars = new LoadVars();
enviar.onLoad = function(){
if(this.exito=="true"){
mensajeTxt.text="Sus datos han sido enviados correctamente a nuestra
base de datos";
}else{
mensajeTxt.text="Sus datos no han sido enviados";
}
}
enviar.nombre=nameTxt.text;
enviar.apellido=surnameTxt.text;
enviar.direccion=addressTxt.text;
enviar.email=emailTxt.text;

enviar.fuente=myCb.value;
if(myCheckbox.selected){
enviar.noticias=true;
}else{
enviar.noticias=false;
}
enviar.comentarios=commentTxt.text;

enterBtn.onRelease=function(){
enviar.sendAndLoad("insertar.php",enviar,"POST");
}

Million thanks,

txusm
Re: Validation rule in PHP doesn't seem to be working Masamune
2/7/2006 2:33:15 PM
txusm,

It looks like you are not assigning the entered values to your enviar object.
Try putting the assignmnet code into the button function. I think you will
probably also need to use an absolute path for your php script, but it depends
on which Flash version you are using. I just put in localhost for testing
purposes, but you will need to use your server address for this. I tested the
code below and it worked with your PHP code.

Vygo


var enviar:LoadVars = new LoadVars();
enviar.onLoad = function() {
if (this.exito == "true") {
mensajeTxt.text = "Sus datos han sido enviados correctamente a nuestra base
de datos";
} else {
mensajeTxt.text = "Sus datos no han sido enviados";
}
};

enterBtn.onRelease = function() {
enviar.nombre = nameTxt.text;
enviar.apellido = surnameTxt.text;
enviar.direccion = addressTxt.text;
enviar.email = emailTxt.text;
enviar.fuente = myCb.value;
if (myCheckbox.selected) {
enviar.noticias = true;
} else {
enviar.noticias = false;
}
enviar.comentarios = commentTxt.text;
enviar.sendAndLoad("http://localhost/insertar.php", enviar, "POST");
};
AddThis Social Bookmark Button