Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 10 of 10

Thread: Problem Getting PHP Variables into Flash

  1. #1

    Problem Getting PHP Variables into Flash

    I've been following this tutorial on using Flash with PHP and mySQL:


    And I'm sort of stumbling at the first fence. I've got the dynamic text field set up with the variable myVar inside a movieclip with the actionScript:

    onClipEvent (load) {
    loadVariables("http://www.mywebsite.co.uk/stuff/phpflash/test.php", this, "GET");
    And I've made and uploaded test.php:

    $x = "abc";
    print "myVar=$x";
    I've opened test.php, and it says 'myVar=abc' like it should.

    Now when I try to preview my flash movie I get this error message:

    Error opening URL 'http://www.mywebsite.co.uk/stuff/phpflash/test.php?myVar=%3Cp+align%3D%22center%22%3E%3C%2Fp %3E'
    As far as I can tell, its sending a bunch of data from the text field to the PHP which is mucking it up (I'm guessing this because when I change the text field's alignment from center to left the error changes to 'align%3D%22left').

    Does anyone know what I'm doing wrong?


  2. #2
    long time i did this but i think it should be:
    print "&myVar=$x";

  3. #3
    God, I'm such an idiot... It wasn't a problem with the script at all, my firewall was simply blocking Flash from connecting to the internet.

    Thanks anyway.

  4. #4
    Ok, new problem. I'm now having problems with it getting the variable out of a mySQL database. What I'm trying to do is search a table for an entry and then use that to set up my variable in Flash.

    So I have this for my php:


    include ("conninfo.php");

    $country = $_GET['country'];

    $query="SELECT * FROM PE_videos WHERE videocountry = $country";

    $result=mysql_query($query) or die ("Nope");
    $numrows = mysql_numrows($result);

    if ($numrows>0)
    print "myVar=$r[videox]";

    echo "None";

    So when I try going to 'http://www.mysite.co.uk/stuff/phpflash/test.php?country=1' in my browser's address bar it says 'myVar=30', as it should. This format worked fine in the first post where the variable was static.

    So I update my actionscript to:

    onClipEvent (load) {
    loadVariables("http://www.mysite.co.uk/stuff/phpflash/test.php?country=1", this, "GET");
    And nothing. Going to this address should use the country=1 part to do the search query on the php page which should provide the myVar variable. I'm nearly 100% sure the php is correct (after all, it does work in the browser), so I'm guessing there's something wrong with that actionscript.

    Any ideas?


  5. #5
    this problem could be caused by caching. I'm not shure that it is but anyway i would advice you to put a random value in your value list tricking your browser to think there will be new info in processing the file

  6. #6
    prstudio's Avatar
    Formerly known as hybrd_dvlpr. This makes life simpler.
    I agree on the caching - what's the actionscript look like?

    Caching information:

    Prevent caching of loaded variables:

    Prevent caching of SWF files:

  7. #7
    Registered User


    Thx man, I was working on it 3 days and i could not get this tutorial running, thx of you it works now hooohhaaa thx alot!

    Note: changing "print "myVar=$x";" to "print "&myVar=$x";" works on my server PHP5.

    Quote Originally Posted by borrob View Post
    long time i did this but i think it should be:
    print "&myVar=$x";

  8. #8

    problem with same tutorial

    I've being trying to implement the same tutorial but I'm stuck.
    I've tried both locally and on my server with no success. I managed to obtain the print result from the php file but, when I go for the database, I get no results.
    I checked and double checked the table and all the scripting and all seems fine. The only problem I can remember of is the correct identification of the db hosting and user. How can I make sure that those are correct?
    thanks in advance

  9. #9


    I use this :


    but it dosent true ,

    here this code is :

    function lv(l, n, t, e, f) { 
                 if (l == undefined) { 
                     l = new LoadVars(); 
                     l.onLoad = function() {
                     var i; 
                     n.htmlText = "";
                     if (t == undefined) { 
                     n.htmlText += "<b>"+this["title"+e]+"</b><br>"; 
                    } else { 
                    for (i=0; i<this.n; i++) {
                    n.htmlText += "<a href='"+this["link"+i]+"'>
     lv(sites_txt, "cycle", null, "sites.php");

    with out change and next code :

    mysql_select_db ("THE DATABASE YOU WANT TO USE");
    $qResult = mysql_query ("SELECT * FROM sites ORDER BY id ASC");
    $nRows = mysql_num_rows($qResult);
    $rString ="&n=".$nRows;
    for ($i=0; $i< $nRows; $i++){
    $row = mysql_fetch_array($qResult);
    $rString .="&id".$i."=".$row['id']."&"."&title".$i."=".$row['title']."&".
    echo $rString."&";

    just change red words .and my sql :

    CREATE TABLE `sites` ( `id` int(11) NOT NULL auto_increment, `link` varchar(100) NOT NULL default '', `title` varchar(100) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=19 ;

    INSERT INTO `sites` VALUES (5, 'www.kirupa.com', 'Kirupa');
    INSERT INTO `sites` VALUES (4, 'www.voetsjoeba.com', 'Voetsjoeba');
    INSERT INTO `sites` VALUES (3, 'www.cannedlaughter.net', 'Canned Laughter');
    INSERT INTO `sites` VALUES (6, 'www.spoono.com', 'Spoono');
    INSERT INTO `sites` VALUES (7, 'www.readymademag.com', 'ReadyMadeMag');
    INSERT INTO `sites` VALUES (9, 'www.weebl.jolt.co.uk', 'Weebl and Bob');
    INSERT INTO `sites` VALUES (10, 'www.aamukaste.org'); ?
    INSERT INTO `sites` VALUES (12, 'www.flipflopflyin.com', 'Flip Flop Flyin'''); INSERT INTO `sites` VALUES (15, 'www.kirupaforum.com', 'KirupaForum');
    INSERT INTO `sites` VALUES (16, 'www.razyr.com/blog', 'Razyr');
    INSERT INTO `sites` VALUES (17, 'senocular.com', 'Senocular');
    INSERT INTO `sites` VALUES (18, 'www.may1reboot.com', 'May 1st Reboot');

    the red line in the top code have problem but it s dosent matter .
    and in the end it s dosent work . why ?
    Last edited by danielelvito; November 5th, 2008 at 09:55 PM.

  10. #10

    variable vanishes in PHP

    Hi all,

    I've overcome most of my problems with this project except for one issue.

    I have a simple one table MySQL database with 4 fields: numero, nome, email, resultado. Sorry about the Portuguese but I think its preferable, for the sake of better understanding my code, which follows:

    $nome = $_POST["nomeVar"];
    //$nome = "rf teste";
    $email = '';
    $results = mysql_query("SELECT email FROM colaboradores WHERE nome = '$nome'")or die(mysql_error());
    while($row = mysql_fetch_assoc($results)) {
        if($email != '') { $email .= ', '; }
        $email .= $row['email'];
    if($email != '') { $email .= ''; }
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
    echo "<colaboradores>\n";
    echo "<email>" . $email . "</email>\n";
    echo "</colaboradores>\n";
    $sendTo = "ricardo.ferreira@pointoview.net";
    $headers = "From: " . $nome;
    $subject = "qemail.php - Resultado de " . $email;
    $message = "O nosso colaborador, " . $nome . ";
    mail($sendTo, $subject, $message, $headers);
    The e-mail is just to check if the "nome" variable is reaching the PHP, which it is. "rf teste" is the name I have inserted in the table to perform all the testing.

    I have a flash quizz game which populates a combobox with the names from the database (through PHP and XML). After answering the questions, each user selects his name and, by pressing a confirmation button, the DB should be queried for the corresponding e-mail address and then return it to flash. The result is also inserted in the DB (no problem with that).

    I just can't understand what's wrong with this. If I assign the "nome" in the PHP, using the commented 2nd line of code, the query is executed and I get the intended e-mail address back, in XML, ready to be read by flash.

    When I send the variable from flash, it reaches PHP and is sent back to me via e-mail but, it fails to reach MySQL as the query isn't executed. Consequently, I get a null result in my flash application.

    Somehow, the variable "nomeVar" sent from flash to php is lost between querying for the corresponding e-mail address and sending the "email" variable back to flash.

    I hope I've clearly put it down for you. Thanks in advance



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012