简体   繁体   中英

passing variable from flash to php and mysql

I have a variable called: name and a variable called score.

I want to send them, on release, to the database on my localhost so i could display them on a page. How can i send the two variables and add them to the mysql DB ?

i'm using actions script 2.0

Thank you

From actionscript 2 you need to use LoadVars .

your_btn.onRelease = function() {
    lv = new LoadVars();
    lv.score = score;
    lv.name = name;
    lv.load("http://localhost/send.php", "POST");
    lv.onLoad = function(src:String) {
        if (src) {
            // OK. src contains the output of the PHP file.
            // i.e. what you "print" or "echo" from php.
            trace(src);
        } else {
            // Problem. Most probably there's an error if src is undefined.
        }
    };
};

From PHP, you can get them from the $_POST array, and add them to mysql using mysqli .

$score = $_POST['score'];
$name = $_POST['name'];

// See a tutorial on how to add them to database.
// You need to connect to MySQL, then do an INSERT query to your table.

Mysqli Docs , or search for some tutorial on MySQL and php, there are plenty of them.

You can pass parameters from Flash to PHP by using GET parameters in your URL.

Start by making URL in Flash like http://www.your-site.org/page.php?name=John&age=21 .

Then access you GET parameters in PHP like $name = $_GET["name"]; $age = $_GET["age"]; $name = $_GET["name"]; $age = $_GET["age"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM