Reputation: 4446
I'm trying to pass a variable from actionscript 3 to php and then store in Mysql. My variable in actionscript is an array. When I try this, I see that add an empty record in Mysql.
var loader : URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://localhost/new.php");
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
var st:String = answer.toString(",");
variables.NAME= st;
request.data = variables;
loader.load(request);
php code:
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("toefl") or die(mysql_error());
$answer=$_POST['st'];
$query = "INSERT INTO test(myanswer) VALUES('$answer')";
mysql_query($query);
?>
Upvotes: 2
Views: 107
Reputation: 865
Your issue comes from the fact that the AS3 sends a data named "NAME", while the PHP tries to retrieve a data named "st".
The source of this error is the following AS3 line of code :
variables.NAME= st;
In this line, NAME
indicate the name that must be used by PHP to be able to read the data. If you want to have the same variable name in the AS3 and PHP, this line should have been :
variables.st = st;
And that's should be all.
Upvotes: 1
Reputation: 157
It may be possible that you are completing the database update before you have defined the values of variables.
Upvotes: 0