×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    157

    Unable to get return value from PHP

    Hi,

    I am unable to get the data from the php using AS 2.0/FL 3.0 code.

    The AS code reads as:


    result_lv = new LoadVars();
    result_lv.num1 = 12;
    result_lv.num2 = 34;

    result_lv.onLoad = function (success)
    {
    if (success)
    {
    trace("Return value from the PHP : " + unescape(this));
    }
    else
    {
    trace("Cannot call the PHP file...");
    }
    }
    result_lv.sendAndLoad("addPHP.php", result_lv, "POST");


    And the 'addPHP.php' contains:

    <?php
    $fVar1 = $_POST['num1'];
    $fVar2 = $_POST['num2'];
    $rtnValue = $fVar1 + $fVar2;
    echo $rtnValue;
    ?>

    I get the following as output when I trace the return from php using 'trace("Return value from the PHP : " + unescape(this));':

    Return value from the PHP : <?php

    $fVar1 = $_POST['num1'];

    $fVar2 = $_POST['num2'];

    $rtnValue = $fVar1 $fVar2;

    echo "supriya";

    ?>&onLoad=[type Function]&num2=34&num1=12


    Though, everthing is fine with the php. I am able to see the execution through the web browser.

    Regards,
    Supriya Tenany

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    107

    Re: Unable to get return value from PHP

    I think you will have to host the PHP on a web server to make it work. You will have to specify the complete URL.

    Ramesh

  3. #3
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    157

    Re: Unable to get return value from PHP

    Hi Ramesh,

    Thanks for your help. The same advice is advocated in http://www.sephiroth.it/tutorials/flashPHP/loadVars/.
    I did get the result this time, but also accompanied by '&onLoad=[type Function]&num2=34&num1=12'. How do I suppress this?

    Regards,
    Supriya Tenany

  4. #4
    Nokia Developer Champion
    Join Date
    Apr 2005
    Location
    Boston
    Posts
    517

    Re: Unable to get return value from PHP

    Ciao,

    you need to define a data to be sent and data to be received. You defined the same object to do both!

    You have this code:
    result_lv = new LoadVars();

    result_lv.sendAndLoad("addPHP.php", result_lv, "POST");

    You should define the data to be sent and object data that receives data from your server:

    data_lv = new LoadVars();
    data_lv.num1 = 12;
    data_lv.num2 = 34;
    data_lv.sendAndLoad("addPHP.php", result_lv, "POST");

    Also the PHP script needs to have the link to the server http://yourserver.com/addPHP.php

    Alessandro

  5. #5
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    157

    Re: Unable to get return value from PHP

    Hi Alessandro,

    Even with the following code, apart from the result value echoed from the php, I also get the following:

    key 90 =
    key onLoad = [type Function]


    AS code:

    result_lv = new LoadVars();
    data_lv = new LoadVars();
    result_lv.num1 = 34;
    result_lv.num2 = 56;

    data_lv.onLoad = function (success)
    {
    if (success)
    {
    for( var prop in this )
    {
    trace (" key " + prop + " = " + this[prop]);
    }
    }
    else
    {
    trace("Cannot call the PHP file...");
    }
    }

    result_lv.sendAndLoad("http://localhost/PhpProject1/index.php", data_lv, "POST");


    PHP code:

    <?php
    $fVar1 = $_POST['num1'];
    $fVar2 = $_POST['num2'];
    $rtnValue = $fVar1 + $fVar2;
    echo $rtnValue;
    ?>



    How can I only extract in the AS, the value that is echoed from the PHP?

    Regards,
    Supriya Tenany

  6. #6
    Nokia Developer Champion
    Join Date
    Apr 2005
    Location
    Boston
    Posts
    517

    Re: Unable to get return value from PHP

    Ciao,

    first I suggest you to review AS from the Adobe documentation since you are mixing up your code!

    Try this:

    result_lv = new LoadVars();
    data_lv = new LoadVars();
    data_lv.num1 = 34;
    data_lv.num2 = 56;

    result_lv.onLoad = function (success)
    {
    if (success)
    {
    for( var prop in this )
    {
    trace (" key " + prop + " = " + this[prop]);
    }
    }
    else
    {
    trace("Cannot call the PHP file...");
    }
    }

    data_lv.sendAndLoad("http://localhost/PhpProject1/index.php", result_lv, "POST");


    Alessandro

  7. #7
    Regular Contributor
    Join Date
    Feb 2010
    Posts
    157

    Re: Unable to get return value from PHP

    hi,

    The following worked:

    result_lv = new LoadVars();
    data_lv = new LoadVars();
    data_lv.num1 = 34;
    data_lv.num2 = 56;

    result_lv.onLoad = function (success)
    {
    trace(unescape(this));
    if (success)
    {
    for( var prop in this )
    {
    trace (" key " + prop + " = " + this[prop]);
    }
    }
    else
    {
    trace("Cannot call the PHP file...");
    }
    }

    //the object in the onData function receives all the value echoed by the PHP
    result_lv.onData = function(dataReceived)
    {
    trace(dataReceived);
    }


    data_lv.sendAndLoad("http://localhost/PhpProject1/index.php", result_lv, "POST");


    Regards,
    Supriya Tenany
    Last edited by supriyaakg; 2010-05-12 at 10:19.

Similar Threads

  1. Dynamic extension loading in PHP (PAMP)
    By didacgil9 in forum Mobile Web Server
    Replies: 3
    Last Post: 2009-02-04, 14:12
  2. return results web services asp .net
    By racsus in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2008-04-15, 09:11
  3. 6280 camera capture - no image returned?
    By neomedia in forum Mobile Java Media (Graphics & Sounds)
    Replies: 10
    Last Post: 2006-11-20, 13:29
  4. 关于Float的问题,急死了,各位帮忙一下,谢谢!
    By show_up in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 4
    Last Post: 2004-08-17, 08:57

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •