Reputation:
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
Upvotes: 0
Views: 1538
Reputation: 7068
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.
Upvotes: 1
Reputation: 4682
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"];
Upvotes: 0