1 Reply Latest reply on Jul 1, 2008 9:50 PM by Noelbaland

    [F8] FLASH Writes to PHP/MYSQL. Working, but question on parallel version

    Nightkarnation
      Ok, Here's the deal:


      FLASH CODE:
      goal: write to php the values of the flash dynamic txt's [SIZE="2"](php will send them to mysql, php code later below)[/SIZE]

      [CODE]// create the LoadVars Objects
      var content_lv:LoadVars = new LoadVars();
      btnUpload.onRelease = function() {
      content_lv.action = "write";
      content_lv.name = txtName.text;
      content_lv.email = txtEmail.text;
      content_lv.location = txtLocation.text;
      content_lv.sendAndLoad(" http://localhost/Test/read.php", content_lv, "POST");
      txtStatus.text = "Upload Succesful";
      };[/CODE]

      WORKING PHP CODE:

      [PHP]
      //write to mysql
      $name=$_POST['name'];
      $email=$_POST['email'];
      $location=$_POST['location'];
      mysql_connect("localhost", "root", "") or die(mysql_error());
      mysql_select_db("learning") or die(mysql_error());
      mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
      Print "Your information has been successfully added to the database.";
      [/PHP]

      Note that the code below that was written in flash...above on the php code its not being used:
      [CODE]content_lv.action = "write";[/CODE]

      NOT WORKING PHP CODE:

      [PHP]//write to mysql.php
      if ($action == "write")
      {
      $name=$_POST['name'];
      $email=$_POST['email'];
      $location=$_POST['location'];
      mysql_connect("localhost", "root", "") or die(mysql_error());
      mysql_select_db("learning") or die(mysql_error());
      mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
      Print "Your information has been successfully added to the database.";
      }[/PHP]

      Here u can notice that im trying to get the value "write" from flash, but for some reason (bad code obviously) php isnt recognizing ($action == "write") and obviously nothing happens

      Any suggestions??
      Looking forward for the solution
      Cheers!
        • 1. [F8] FLASH Writes to PHP/MYSQL. Working, but question on parallel version
          Noelbaland Level 1
          Hello there,

          I can see in your PHP script that your not testing (or assigning) your $action variable. Test it with the isset command first and then assign it to the variable (see code below).

          Also, since you're using sendAndLoad you should create another LoadVars object to handle the errors and success values from the server.

          Here is a version of your code that I've recreated using the points above. Read the comments and change it accordingly. Hope it helps!