Jump to content

Recommended Posts

loading variables into flash from a php file.

Hi guys. 

I wonder this has been discussed many times & having gone through many such answers I still seem not to get a reply to my problem.

 

So i have a program in flash, which generates a button which when clicked gets a set of variables from a php file called testdata.php.

 

Now this tesfile.php when run standalone generates correct values of variables & displays them. 

 

However when i change it to be able to send it to a flash file ( make changes in 

echo "&db_w_var1=$db_val1"; ) like this. the values I receive in flash are odd. in fact i get this $db_val1";exactly this for the first variable. I get this string instead of receiving an integer value 4 or maybe even a string value '4'. 

 

So can anyone looking at this tell me what could be going wrong. The following is a part of code which calls the php file to get the value of variables: 

 var w_WS;        // Database returned Written Sums    var w_WT;        // Database returned Written Time
    var w_ST;        // Database returned Sum Type ( written or visual or oral)
    var w_end;
    
    lv1.dataType = "written";
    lv1.w_sums_correct= w_sums_correct;
    lv1.w_time = w_time;
    
/////////// for localhost ///////////////////    
    lv1.sendAndLoad(path+"testdata.php",lvIn1,"POST"); // sends data values of lv1 variabless
                                                      // and GETS lvIn1 value
/////////// for display on a webpage (_blank) ///////////////////
//    lv1.send(path + "sessdata1.php", "_blank", "POST"); // or GET


    lvIn1.onLoad = function(success){
        if(success){
            w_WS = lvIn1.db_w_var1;
            w_WT = lvIn1.db_w_var2;
            w_ST = lvIn1.db_w_var3;            
            w_end = lvIn1.db_w_end; 
                    
        written_data = " WT = "+w_WT;    //  " WS = "+w_WS + "  Type = "+w_ST + "End = "+w_end; 
        }    // end success

Thanks to all for any help. This has me losing my brains. please help the gurus.    

Link to comment
https://forums.phpfreaks.com/topic/280636-passing-variables-from-php-to-flash/
Share on other sites

Hi, Glad to receive a reply. It is encouraging to know that flash is receiving exactly what php is sending to it. Before I post the code i would like to post the output of my php code. 

 

hmmm ok this does not permit me to paste a picture( snapshot) of my output so i'll just write it below:

 

=========== Output of the php file ===============

var11=4

var12=4

wsc=4wtt=4

Val1=4

Val2=4

Val3=written

&db_w_var1=4&db_w_var2=4&db_w_var3=written&db_w_end=0

======================================================

 

The last line of the output shows the correct values but when i check the first value in flash

w_WS = lvIn1.db_w_var1;

 

and display this one value in a text field in flash I get 

 

$db_val1"; 

 

as the output. 

OK  so here is the php file 

<?php


$dt = "data1";          //$_POST["dataType"];               //

switch ($dt)
{
case "data1":
        $var11 =  4;             // $_POST["f_var1"];             //          2; debug 4
        $var12 =  4;             // $_POST["f_var2"];                     //          3; debug 5

        $var11 = $var11 * 1;
        $var12 = $var12 * 1;
        $send_val = array($dt,$var11,$var12);
        $db_val = get_val($send_val);                              //

        break;

case "data2":
        $var21 =  5;            //$_POST["f_var1"];             //          2; debug 4
        $var22 =  5;            //$_POST["f_var2"];                     //          3; debug 5

        $var21 = $var21 * 1;
        $var22 = $var22 * 1;
        $send_val = array($dt,$var21,$var22);
        $db_val = get_val($send_val);

        break;

default:
          echo " Bad Choice - cannot identify $datatype";
} // end switch

$db_val1=$db_val[0];
$db_val2=$db_val[1];
$db_val3=$db_val[2];
$d_end='0';


//$dbw_WS = $dbw_WS*1;
//$dbw_WT = $dbw_WT/1;
//$dbw_ST = $dbw_ST;

echo "Val1 =".$db_val1;
echo "<br>";
echo "Val2 =".$db_val2;
echo "<br>";
echo "Val3 =".$db_val3;
echo "<br>";


echo "&db_w_var1=$db_val1";
echo "&db_w_var2=$db_val2";
echo "&db_w_var3=$db_val3";
echo "&db_w_end=$d_end";


//////////////////////////////////////////////////////////

function get_val($vals)
{
$db = "test";
$table = "testdata";
$con = mysqli_connect("localhost","root","",$db);

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$dtype = $vals[0];
echo " VALS = ".$dtype;
$query = "SELECT * FROM $table WHERE status IS NULL || status = '0' ";
        mysqli_query($con,$query) or die (mysqli_error($con));

        if(mysqli_affected_rows($con)==1)

           { //a                                      //
                $result = mysqli_query($con, $query);
                $row=mysqli_fetch_assoc($result);
                mysqli_free_result($result);

                $id = $row['id'];

           switch($dtype)
             {
                  case "data1":
                  
                  $var11 = $vals[1];
                  $var12 = $vals[2];

                  echo "---------------UPDATEing VAR1---------------";
                  echo"<br>";
                  echo " ID = ".$id;
                  echo"<br>";
                  echo "var11 = ".$var11;
                  echo"<br>";
                  echo "var12 = ".$var12;
                  echo"<br>";

                  $query = "UPDATE $table SET var11 = '$var11', var12 = '$var12'  WHERE id = '$id'";

                  $result = mysqli_query($con, $query);     //
                     if($result)         //
                         {

                             $query = "SELECT * FROM $table WHERE id = '$id'";
                             $result1 = mysqli_query($con,$query);  //

                //
                             if($result1)
                                  {
                                  $row=mysqli_fetch_assoc($result1);
                                  mysqli_free_result($result1);

                      //
                                  $wsc = $row['var11'];
                                  $wtt = $row['var12'];

                                  $var_result =array($wsc,$wtt,"written");
                        //

                                  echo "wsc = ".$wsc;
                                  echo "wtt = ".$wtt;

                                  echo " Record VAR1 Inserted. <br>";
                                  }
                        }
                        else{ echo " NOT INSERTED";}
                        break;

                  case "data2":
                  
                  $var21 = $vals[1];
                  $var22 = $vals[2];
                  
                  echo "---------------UPDATEing VAR2---------------";
                  echo"<br>";
                  echo " ID = ".$id;
                  echo"<br>";

                  echo"<br>";
                  echo "var21 = ".$var21;
                  echo"<br>";
                  echo "var22 = ".$var22;
                  echo"<br>";

                  $query = "UPDATE $table SET var21 = '$var21', var22 = '$var22' WHERE id = '$id'";

                              $result = mysqli_query($con, $query);     //
                              if($result)         //
                              {

                                  $query = "SELECT * FROM $table WHERE id = '$id'";
                                  $result1 = mysqli_query($con,$query);  //

                       //
                                  if($result1)
                                  {
                                  $row=mysqli_fetch_assoc($result1);
                                  mysqli_free_result($result1);

                      //            echo " Row = ".$row;
                                  $vsc = $row['var21'];
                                  $vtt = $row['var22'];

                                  $var_result =array($vsc,$vtt,"written");
                        //          mysqli_close($con);

                                  echo "vsc = ".$vsc;
                                  echo "vtt = ".$vtt;

                                  echo " Record VAR2 Inserted. <br>";
                                  }

                              }
                              else{ echo " NOT INSERTED";}
                      break;
                           
                default : " Cannot recognise the data";
                      break;
             }  // end switch
            }   // end if
        else
           {
                $query = "SELECT * FROM $table ORDER BY id DESC LIMIT 0,1";
                if($result = mysqli_query($con,$query))
                    { // j
                        $row=mysqli_fetch_assoc($result);
                        $id = $row['id'];
                    } // j end
                else die(mysqli_error($con));

                // $id = $lastrow+1;

                echo " Before INSERT ";

                echo " var11 = ".$var11;
                echo "<br>";
                echo " var12 = ".$var12;
                echo "<br>";

                $query = "INSERT into $table ( var11, var12) VALUES ('$var11','$var12')";

                $result=mysqli_query($con, $query) or die(mysqli_error($con));    //
                echo " After INSERT ";
                echo " id = ".$id;

                        if(!$result){ die( 'Error: ' . mysqli_error($con)); }
                        else {  // k        //

                               $query = "SELECT * FROM $table WHERE id = '$id'";
                                          $result1 = mysqli_query($con,$query);  // or die (mysqli_error($con));

                                          if($result1)
                                          { // l
                                          $row=mysqli_fetch_assoc($result1);
                                          mysqli_free_result($result1);

                              //            echo " Row = ".$row;
                                          $wsc = $row['var11'];
                                          $wtt = $row['var12'];

                                          $var_result =array($wsc,$wtt,"written");

                                          echo "wsc = ".$wsc;
                                          echo "wtt = ".$wtt;

                                          echo " Record Written Inserted. <br>";
                                          }  // l end
                                          else { die( 'Record not inserted. ERROR: ' . mysqli_error($con)); }

                               } // k end

                echo " UPDATING SESSION STATUS ";

                $query = "SELECT * FROM $table WHERE id = '$id'";
                $result1 = mysqli_query($con,$query);  // or die (mysqli_error($con));

                if($result1)
                  {
                     $row=mysqli_fetch_assoc($result1);
                     mysqli_free_result($result1);

                     $WS = $row['var11'];
                     $VS = $row['var21'];
                  }

                if($WS==1 && $VS==1 )      //
                  {
                        $query = "UPDATE $table SET status = '1' WHERE id = '$id' ";
                  }
                  
                 $result = mysqli_query($con, $query);     // or die (mysqli_error($con));
                 if($result)         //
                   {
                      echo " Updated SessionStatus <br>";
                   } else echo " Could not Update SessionStatus <br>";




   } // end get_val
    return ($var_result);

}



?>

Hope someone can help me figure this one. I do feel this is a typecast issue but have no idea how to deal with it. Thanks loads for any help which i desperately need here.

i'm going to guess the "URL" your flash is requesting is actually the local operating system filepath/filename of the php file, not the URL of the php file through your web server. are you browsing to the URL of your flash file (http://localhost/someanme.swf) so it would be requested through your web server or are you running it in an IDE?

Hi ! I am not sure what you are asking but I'll say what i am doing now.  As of now I am using it through the flash IDE on my machine. I have xamp installed and so a local server exists on my machine. But for this example I am using the flash IDE and running my flash file and trying to get the variables into the flash, In fact thats all I am trying to do as of now in this example. Just to get the right variables loaded and displayed in flash. Part of the flash code is given by me in the first message of this thread.

 

Once i get the flash variables correct I do intend to embed the flash in HTML and host it on a server. Still far from there. I hope I have answered your question. If not please ask more.

 

Thanks Mac n all else who would be interested in taking this on.

hmmm ! well thats where i came from to where I am now. This code was a part of a larger program where the flash was embedded in the html/php. I was facing this issue there ( in the embedded movie page) so i created this separate bit of code to find the problem in the actual program. But since you ask I'll try this now. It wont take any time since flash creates the HTML too. So here i go to flash and will revert the results.

 

OK so like in the actual code movie this movie also returns the absolute same result. The output is the variable    $db_val1";

 

As you can see flash / HTML outputs the variable wid the ending quotes and the semi-colon, whose value it should actually be outputting which in my case should be 4 since thats the value I have sent to the code.

 

The lines which outputs the flash / HTML are these   :-

 

lv1.sendAndLoad(path+"testdata.php",lvIn1,"POST"); // sends data values of lv1 variabless and GETS lvIn1 value
/////////// for display on a webpage (_blank) ///////////////////

lvIn1.onLoad = function(success){
if(success){
w_WS = lvIn1.db_w_var1;
w_WT = lvIn1.db_w_var2;
w_ST = lvIn1.db_w_var3;
w_end = lvIn1.db_w_end;

written_data = " WT = "+w_WT;

}

 

where written_data is a variable attached to a dynamic textbox. and thats where the value is displayed. Can you detect any problem wid this code here ? Syntax or logic ?? I don't think so but still just in case.

 

Another interesting observation is that if i change on line 34 

34. $db_val1=$db_val[0]; to $db_val1=4;

the result is still the same !! i.e.  $db_val1";

and if I force the value on line 52 as below

 

echo "&db_w_var1=4";

 

i.e. equate the value to 4 the out put is 4"; !! Isn't that strange ?

If that is any help in providing a clue to this one.

 

Thanks again. Please help me solve this.  

 

Edited by ajoo

Hi Mac, I got it working. Since I am using Flash 2.0 its publishing the swf file and things is very confusing. The issue lay with the path. Once i got that correct ( its different for flash IDE and as an HTML invoked by localhost, it worked. Thanks loads since you had that in mind and you gave that pointer to me.

 

Grateful and Thanks again.

Hi guys back again with another head swirler, at least for me. Needless to say I have been trying to figure it out for 2 days now. And I was sure I cud do it without help but guess it was a very sly one who refused to budge. 

 

So i have a Flash layer called TIMER where I have the code to display the timer and this layer also processes the time code where it uses variables like myMinute and mySeconds. It uses these two to store the time and then uses these to find the time elased till a BUTTON is pressed. 

 

This button triggers the handler (onPress()) which has a function say send_values() to create a set of values to send to the php. The function send_values() is described / written in the Actions Layer. Inside this layer, the two variables mySeconds and myMinutes are used to send the time to php using a variable lv1.time_in_seconds = myMinites*60+mySeconds; like this lv1.send(path+"data.php", "_blank", POST" ).

 

 

======= DEFINED IN FLASH========
var mysec:Number=mySeconds;
var mymin:Number=myMinute;
var vTimNsec=mymin*60+mysec;
 
========= SENT TO PHP ===========
lv1.v_sums_correct = mymin;
lv1.v_time_in_seconds = mysec;
lv1.v_delay_digit_ms = vTimNsec;
 

 

If I run this in the Flash (2.0) IDE and trace the values OR display the values in a dynamic text box, I am shown the correct values. 

 

BUT if i run this from a localhost with the flash embedded in the HTML file I get values 

 

vis_sum_corr = undefined         // This is mymin
vis_sum_tme = undefined         // This is mysec
vis_dig_dely = NaN                 // This is (mymin*60+mysec)

 

So the values displayed in Flash are displayed absolutely correct and the moment I send them to PHP they are changed to undefined and NaN. 

 

Can someone please guide me what could be wrong here. I have gone nuts trying. Desperately need some gurus to sort this out. 

 

Thanks all.

Edited by ajoo
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.