Comunidad de diseño web y desarrollo en internet online

CONECTAR FLASH CON BASE DE DATOS MYSQL VIA RHP

Citar            
MensajeEscrito el 03 May 2008 01:38 pm
Hola a todos, tengo un problema para poder registrar variables en una base de datos MySQL con flash via PHP, de algún modo no inserta las variables en el PHP o al menos eso es lo q creo...
Los campos en la base de datos se llaman igual a las variables pero sin la \"v\" al final, creo q no importa el nombre en la tabla sino el orden en que se colocan para ser insertados.
MUCHAS GRACIAS POR LA ASISTENCIA PRESTADA

aquí les publico los 2 códigos:

- Flash:

sexo.maxChars = 1;
fechanac.maxChars = 10;
fechanac.text = \"aaaa-dd-mm\";
enviar = function () {
myLoadVars = new LoadVars();
if (email.text == \'\') {
email.text = \"Inserta un Email válido\";
} else if (nombre.text == \'\') {
nombre.text = \"Inserta un Nombre válido\";
} else if (apellido.text == \'\') {
apellido.text = \"Inserta un Apellido válido\";
} else if (direccion.text == \'\') {
direccion.text = \"Inserta una Dirección válida\";
} else if (pais.text == \'\') {
pais.text = \"Inserta un País válido\";
} else if (fechanac.text == \'\') {
fechanac.text = \"Inserta una Fecha válida\";
} else {
myLoadVars.sendAndLoad(\"http://www.geodestinos.com/insert.php\", \"myLoadVars\", \"POST\");
myLoadVars.emailv = email.text;
myLoadVars.nombrev = nombre.text;
myLoadVars.apellidov = apellido.text;
myLoadVars.direccionv = direccion.text;
myLoadVars.paisv = pais.text;
myLoadVars.fechanacv = fechanac.text;
myLoadVars.sexov = sexo.text;
myLoadVars.onLoad = function() {
if (this.correcto == \"ok\") {
mensaje.text = \"Registro Satisfactorio\";
nombre.text = \"\";
email.text = \"\";
apellido.text = \"\";
pais.text = \"\";
direccion.text = \"\";
fechanac.text = \"\";
sexo.text = \"\";
} else {
mensajev.text = \"No se pudo realizar el registro, intenta de nuevo\";
}
};
}
};
borrar = function () {
nombre.text = \"\";
email.text = \"\";
apellido.text = \"\";
pais.text = \"\";
direccion.text = \"\";
fechanac.text = \"\";
sexo.text = \"\";
};
enviar_btn.onRelease = enviar;
borrar_btn.onRelease = borrar;


Y AQUI EL PHP

<?PHP
//conexión a la base de datos
$host = \"localhost\";
$user = \"*********\";
$pass = \"********\";
$bbdd = \"*********\";
$conexion = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($bbdd,$conexion) or die(mysql_error());


//Inserción de datos

$Query = \"INSERT into usuarios values (\'0\', \'\"$_POST[\'emailv\']\"\', \'\"$_POST[\'nombrev\']\"\', \'\"$_POST[\'apellidov\']\"\' \'\"$_POST[\'direccionv\']\"\', \'\"$_POST[\'paisv\']\"\', \'\"$_POST[\'fechanacv\']\"\', \'\"$_POST[\'sexov\']\"\')\";



mysql_db_query ($bbdd ,$Query ,$conexion)
echo (\"$correcto = \"ok\");

mysql_close($conexion)


?>

Por mike2586

8 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 03 May 2008 01:50 pm

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 03 May 2008 02:04 pm
nop, está bien el link, es donde está alojado el PHP con el código que publique...

Por mike2586

8 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 03 May 2008 02:19 pm
Pulso en el link y ooops:

Parse error: syntax error, unexpected T_VARIABLE in /home/geodesti/public_html/insert.php on line 20

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 03 May 2008 03:49 pm
corregi los codigos, y ahora logro q cree el registro en la base de datos, pero lo hace en blanco, no toma las variables... y tampoco me genera el mensaje de registro... aqui dejo el código a ver...


flash:
sexo.maxChars = 1;
fechanac.maxChars = 10;
fechanac.text = "aaaa-dd-mm";
enviar = function () {
myLoadVars = new LoadVars();
recLoadVars = new LoadVars();
if (email.text == '') {
email.text = "Inserta un Email válido";
} else if (nombre.text == '') {
nombre.text = "Inserta un Nombre válido";
} else if (apellido.text == '') {
apellido.text = "Inserta un Apellido válido";
} else if (direccion.text == '') {
direccion.text = "Inserta una Dirección válida";
} else if (pais.text == '') {
pais.text = "Inserta un País válido";
} else if (fechanac.text == '') {
fechanac.text = "Inserta una Fecha válida";
} else {
myLoadVars.sendAndLoad("http://www.geodestinos.com/insert.php", recLoadVars, "POST");
myLoadVars.emailv = email.text;
myLoadVars.nombrev = nombre.text;
myLoadVars.apellidov = apellido.text;
myLoadVars.direccionv = direccion.text;
myLoadVars.paisv = pais.text;
myLoadVars.fechanacv = fechanac.text;
myLoadVars.sexov = sexo.text;

}
recLoadVars.onLoad = function(success) {
if (trace (correcto)) {
mensaje.text = "Registro Satisfactorio";
nombre.text = "";
email.text = "";
apellido.text = "";
pais.text = "";
direccion.text = "";
fechanac.text = "";
sexo.text = "";
} else {
mensajev.text = "No se pudo realizar el registro, intenta de nuevo";
}
};


};
borrar = function () {
nombre.text = "";
email.text = "";
apellido.text = "";
pais.text = "";
direccion.text = "";
fechanac.text = "";
sexo.text = "";
};
enviar_btn.onRelease = enviar;
borrar_btn.onRelease = borrar;

PHP:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>insert.php</title>
</head>
<body>
<?PHP
//conexión a la base de datos
$host = "localhost";
$user = "geodesti_mike";
$pass = "12348765";
$bbdd = "geodesti_Geodestinos";
$conexion = mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($bbdd,$conexion) or die(mysql_error());


$email = $_POST['emailv'];
$nombre = $_POST['nombrev'];
$apellido = $_POST['apellidov'];
$direccion = $_POST['direccionv'];
$pais = $_POST['paisv'];
$fechanac = $_POST['fechanacv'];
$sexo = $_POST['sexov'];

//Inserción de datos

$Query = "INSERT INTO usuarios (id, email, nombre, apellido, direccion, pais, fechanac, sexo) VALUES ('0', '$email', '$nombre', '$apellido', '$direccion', '$pais', '$fechanac', '$sexo')";



$correcto = mysql_db_query ($bbdd ,$Query ,$conexion) or die(mysql_error());

echo ("$correcto");

mysql_close($conexion)


?>



</body>
</html>

Por mike2586

8 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 03 May 2008 04:05 pm
Estás enviando antes de setear los valores. Mueve la línea del sendAndLoad al final

....
myLoadVars.sexov = sexo.text;
myLoadVars.sendAndLoad("http://www.geodestinos.com/insert.php", recLoadVars, "POST");

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 03 May 2008 04:33 pm
muchas gracias!!! listo por ese lado, ahora, hay un error en la parte para q me devuelva el mensaje de si el registro fue satisfactorio o no, lo q no estoy seguro es si es en el PHP o en el llamado desde Flash... si me puedes dar esa ultima mano... de verdad gracias por la ayuda...

Por mike2586

8 de clabLevel



Genero:Masculino  

msie7
Citar            
MensajeEscrito el 03 May 2008 04:45 pm
Sería algo así:

$correcto = mysql_db_query ($bbdd ,$Query ,$conexion) ;
if($correcto) echo "status=ok"; else echo "status=error";

En Flash

Código :

recLoadVars.onLoad = function(success) {
  if(success){
    if(this.status=="ok") mensaje.text = "Registro Satisfactorio";
    else mensaje.text = "Error";
  } else mensaje.text = "Error";
}


Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.