6 Replies Latest reply on May 3, 2008 9:30 AM by kglad

    FLASH + MySQL DB via PHP

    Miguel2586
      Hello everybody, i have a problem registering variables on MySQL database with flash via PHP, i can't get the variables to be inserted on MySQL DB, i guess it's a comm problen between flash and PHP
      The field names on the DB are the same of the variables you can see here but without the \"v\" in the end, i think there's no problem with the name of the fields on the DB but with the order to insert them
      THANKS A LOT FOR YOUR SUPPORT

      here are the 2 codes:

      - 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;


      - 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)


      ?>
        • 1. Re: FLASH + MySQL DB via PHP
          kglad Adobe Community Professional & MVP
          why are you escaping all your quotes? and use two different loadvars instances; one to send and one to load.
          • 2. Re: FLASH + MySQL DB via PHP
            Miguel2586 Level 1
            the escaping quotes is some problem i got when i pasted the code... and thnx for the advice... i'm gonna try it
            • 3. Re: FLASH + MySQL DB via PHP
              Miguel2586 Level 1
              well... i've made the second instance, but still doesn't work... in fact, before it returned the error message, now it doesn't do anything... here's the updated flash code:

              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 {
              recLoadVars.onLoad = function(success) {
              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";
              }
              };

              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;

              }
              • 4. Re: FLASH + MySQL DB via PHP
                kglad Adobe Community Professional & MVP
                it looks like you're calling your php script before your variables are defined.

                and did you fix your php file?
                • 5. Re: FLASH + MySQL DB via PHP
                  Miguel2586 Level 1
                  ok... here there are some updates to the codes... i've managed to actually create the entry on the database but it looks empty, it's not getting the variables, and also, it doesn't trace the message for success...

                  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>
                  • 6. Re: FLASH + MySQL DB via PHP
                    kglad Adobe Community Professional & MVP
                    again, "it looks like you're calling your php script before your variables are defined."