#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    20
    Rep Power
    0

    Lightbulb Interaction between PHP, MySQL and Macromedia Flash MX


    Hello, I have recently started to study Macromedia Flash MX and found it ideal for the creation of very impressive graphic intefaces. Unfortunately, its inability to save data either on the hard disk or on a server is a serious problem preventing the creation of any database whatsoever.

    As soon as I learned that Flash can interact with PHP and, through this programming language, manage MySQL databases, I searched for tutorials which could explain to me how to do that.

    My search was only partially successful, in that I could only learn how to query a database by means of a PHP file "launched" by Flash and get the results of the query within Flash.

    To sum up, I created a simple frame in Flash containing a button and a textbox accepting HTML code. Then I assigned the variable name "Results" to the textbox and inserted the following code in the on_release event of the button:

    //***START OF CODE***
    on (release) {
    loadVariablesNum("getfile.php",0);
    }
    //***END OF CODE***

    The code above allows Flash to execute the "getfile.php" file containing the following code:

    //***START OF CODE***
    <?php

    @mysql_connect("localhost", "root", "") or die ("Failed to connect!");
    @mysql_select_db("contacts") or die ("Could not open DB");

    $result1 = mysql_query("select * from customers");

    print "Results=";
    echo "<h1>Search Results</h1><br>";

    while($row=mysql_fetch_array($result1))
    {
    $nome=$row["name"];
    echo "<b>Name: </b>$name<br>";

    $phone=$row["phone"];
    echo "<b>Phone number: </b>$phone<br><br>";
    }

    ?>
    //***END OF CODE***

    As you know, the line
    print "Results=";
    inserts the expression "Results=" at the beginning of the output generated by PHP, so that Flash can import such output into its textbox called "Results".

    So far, so good. What is still unclear to me is how to send the content of a textbox from Flash to PHP. This would allow me to create the graphic interface of a database in Flash and pass the data to PHP. Finally, PHP would take care of inserting this data into a MySQL database.

    What I really need is simply to learn how to translate the following PHP instructions into Flash code:

    $variabile = $_POST['textbox'];
    echo "$variabile";

    Of course, the code above belongs to a form in which the method property is set to "post". Nevertheless, the textbox sending the data should belong to Flash rather than an HTML form. If I managed to do that, I could easily save the data sent by Flash in a MySQL database.

    I have installed PHP v.4.2.3 on a Windows XP Home Edition system equipped with an Apache HTTP Server v.1.3.24 and MySQL v.4.0.3.

    Thanks in advance for your help.

    Pasquale Esposito
    Perugia (Italy)
    http://web.tiscali.it/espositopasquale/
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Location
    Hong Kong
    Posts
    31
    Rep Power
    12
    Assume that you have a variable call "var1" on _root and its value is "100".
    loadVariablesNum("*.php?abc=" + var1, 0);

    *.php
    PHP Code:
    echo "the result is:$abc";//the result is:100 
    Last edited by ddlam; December 30th, 2002 at 03:52 PM.
    A green newbie in PHP
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Posts
    20
    Rep Power
    0

    Thanks: Problem solved!


    Dear ddlam.

    thanks for your help but I had already found the solution to my problem. Now I know that to send data from a textbox in Flash

    MX to a PHP file, it is enough to use the method

    loadVariablesNum("myfile.php", 0, "POST");

    Then, inside the PHP file, I must recall the Flash variable in the following way:

    //***START OF CODE***
    <?php

    //Retrieves variable from Flash
    $myvar = $_POST['textbox'];

    //varDisplay is the variable name assigned to the Flash textbox
    echo "varDisplay=The user typed in this expression: ";
    echo "$myvar";

    ?>
    //***END OF CODE***

    Thanks again.

    Pasquale Esposito
    Perugia (Italy)
    http://web.tiscali.it/espositopasquale/

IMN logo majestic logo threadwatch logo seochat tools logo