sendandload to php problem

Ask a Question related to Macromedia Flash Data Integration, Design and Development.

  1. #1

    Default sendandload to php problem

    I thought this should be relatively straightforward but ....

    I want to send two variables from a swf to a php script.
    The php script then inserts them into a table row in a mySQL database.
    I can do this with the loadVars send() function. I have this working. However,
    this opens a new browser window.
    I want the php script to run in the background (i.e. no new window).
    I have tried the sendandload() function with various combinations of GET's and
    POST's but no joy.
    It is sending the variablesand the load returns success but I'm not getting
    updates in the table.
    It seems that the php script is not running? I'm fairly new to php. Does it
    need to be in a browser to execute?
    Heres the code

    //AS

    _global.sendNames = function(First, Last) {
    var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
    if (success) {
    trace("LOAD Success");
    trace(result_lv.PHPresult);
    } else {
    trace("LOAD Fail");
    trace(result_lv.PHPresult);
    }
    };
    var send_lv:LoadVars = new LoadVars();
    send_lv.firstName = First;
    send_lv.lastName = Last;
    trace("SENDING NAMES");
    trace(First);
    trace(Last);
    send_lv.sendAndLoad("http://localhost/experiment/usersUpdate.php",
    result_lv, "POST");
    }

    //PHP
    <?
    $host = "localhost";
    $user = "root";
    $pass = "28phaedruS";

    $firstName = $_GET['firstName'];
    $lastName = $_GET['lastName'];

    $db="results";
    $link = mysql_connect($host, $user, $pass);
    if (! $link)

    $PHPresult="Couldn't connect to MySQL";
    mysql_select_db($db , $link)
    or die("Couldn't open $db: ".mysql_error());

    mysql_query ("INSERT INTO users(firstName,lastName) VALUES
    ('$firstName','$lastName')");

    echo("firstName=".$firstName."<br />");
    echo("lastName=".$lastName."<br />");
    mysql_close($link);
    ?>
    Any Ideas?


    connoru Guest

  2. Similar Questions and Discussions

    1. sendAndLoad()
      attached is an xml very simple script in flash swf - however i do not know how to write the server side .asp can someone tell me what should be the...
    2. XML sendAndLoad problem
      I have a simple sendAndLoad XML request that works perfectly on 95% of the computers I have used. I have check crosssite stuff and everything i can...
    3. https:// problem with sendandload
      :confused; I am having a problem with sendAndLoad on a secure site. Has anyone run across this before? In Internet Explorer it does not work at...
    4. Need php help using xml sendandload
      info: var bc_xml:XML = new XML(email); var email:String = "<email>ck1mark@hotmail.com</email>"; bc_xml.sendAndLoad(bc_url, bc_xml, "POST"); how...
    5. asp and sendAndLoad
      I have a small app that sends and loads varsbetween flash and asp. I have a text field that allows the user to add new records to a DB. On the same...
  3. #2

    Default Re: sendandload to php problem

    1. Only PHP in the file. No html in other words.
    2. No whitespace (sp cr tab) before the first php tag <?php or after the
    last php tag ?>
    3. echo back URL encoded variable pairs

    var1=value&var2=value&var3=value:

    echo "firstName=" . $firstName;
    echo "&lastName=" . $lastName;

    4. If you are using just the loadVars send method, then the PHP should not
    echo any values back. Otherwise you need to use the sendAndLoad method and
    send back URL encoded variable pairs.


    5. You really do not want to use die and other PHP functions that result in
    sending text. Rather build PHP code that captures the errors and if needed
    return URL vars back to Flash for UI feedback.

    echo "&success=" . $success ; // figured elsewhere
    echo "&returnMessage=" . "Couldn't open $db: " . mysql_error() ; // If you
    need to see in Flash for debugging


    Here is a basic send and return with loadVars and PHP I use in training
    courses.

    [url]http://www.hosfordusa.com/ClickSystems/courses/flash/examples/LoadVars/Ex01/LoadVarsEx01.php[/url]

    --
    Lon Hosford
    [url]www.lonhosford.com[/url]
    May many happy bits flow your way!
    "connoru" <webforumsuser@macromedia.com> wrote in message
    news:dns17k$q35$1@forums.macromedia.com...
    I thought this should be relatively straightforward but ....

    I want to send two variables from a swf to a php script.
    The php script then inserts them into a table row in a mySQL database.
    I can do this with the loadVars send() function. I have this working.
    However,
    this opens a new browser window.
    I want the php script to run in the background (i.e. no new window).
    I have tried the sendandload() function with various combinations of GET's
    and
    POST's but no joy.
    It is sending the variablesand the load returns success but I'm not getting
    updates in the table.
    It seems that the php script is not running? I'm fairly new to php. Does it
    need to be in a browser to execute?
    Heres the code

    //AS

    _global.sendNames = function(First, Last) {
    var result_lv:LoadVars = new LoadVars();
    result_lv.onLoad = function(success:Boolean) {
    if (success) {
    trace("LOAD Success");
    trace(result_lv.PHPresult);
    } else {
    trace("LOAD Fail");
    trace(result_lv.PHPresult);
    }
    };
    var send_lv:LoadVars = new LoadVars();
    send_lv.firstName = First;
    send_lv.lastName = Last;
    trace("SENDING NAMES");
    trace(First);
    trace(Last);
    send_lv.sendAndLoad("http://localhost/experiment/usersUpdate.php",
    result_lv, "POST");
    }

    //PHP
    <?
    $host = "localhost";
    $user = "root";
    $pass = "28phaedruS";

    $firstName = $_GET['firstName'];
    $lastName = $_GET['lastName'];

    $db="results";
    $link = mysql_connect($host, $user, $pass);
    if (! $link)

    $PHPresult="Couldn't connect to MySQL";
    mysql_select_db($db , $link)
    or die("Couldn't open $db: ".mysql_error());

    mysql_query ("INSERT INTO users(firstName,lastName) VALUES
    ('$firstName','$lastName')");

    echo("firstName=".$firstName."<br />");
    echo("lastName=".$lastName."<br />");
    mysql_close($link);
    ?>
    Any Ideas?


    Motion Maker Guest

  4. #3

    Default Re: sendandload to php problem

    you can't send using POST from Flash and then read with $_GET in PHP. You must of course read from $_POST["firstName"]
    flash-hero Guest

  5. #4

    Default Re: sendandload to php problem

    Hi, did you success in making php handle and store data in background? if so could you please give me a shot?

    Thanks
    Samad Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139