0

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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"];

3 Comments

You might be in a lot of trouble if you have some weird characters in your url.
Fixed that. You can also use POST method. It largely depends on the data you are transferring.
Agreed. Just to make it clear to the OP, in case he would have some troubles (spaces, special characters, ...).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.