Ok, Here's the deal:
FLASH CODE:
[B]goal:[/B] write to php the values of the flash dynamic txt's
[I][SIZE="2"](php will send them to mysql, php code later below)[/SIZE][/I]
[CODE]// create the LoadVars Objects
var content_lv:LoadVars = new LoadVars();
btnUpload.onRelease = function() {
content_lv.action = "write";
content_lv.name = txtName.text;
content_lv.email = txtEmail.text;
content_lv.location = txtLocation.text;
content_lv.sendAndLoad("http://localhost/Test/read.php", content_lv, "POST");
txtStatus.text = "Upload Succesful";
};[/CODE]
WORKING PHP CODE:
[PHP]
//write to mysql
$name=$_POST['name'];
$email=$_POST['email'];
$location=$_POST['location'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("learning") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
Print "Your information has been successfully added to the database.";
[/PHP]
Note that the code below that was written in flash...above on the php code its
not being used:
[CODE]content_lv.action = "write";[/CODE]
NOT WORKING PHP CODE:
[PHP]//write to mysql.php
if ($action == "write")
{
$name=$_POST['name'];
$email=$_POST['email'];
$location=$_POST['location'];
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("learning") or die(mysql_error());
mysql_query("INSERT INTO `data` VALUES ('$name', '$email', '$location')");
Print "Your information has been successfully added to the database.";
}[/PHP]
Here u can notice that im trying to get the value "write" from flash, but for
some reason (bad code obviously) php isnt recognizing [B]($action ==
"write")[/B] and obviously nothing happens
Any suggestions??
Looking forward for the solution
Cheers!
Noelbaland - 02 Jul 2008 05:51 GMT
Hello there,
I can see in your PHP script that your not testing (or assigning) your $action
variable. Test it with the isset command first and then assign it to the
variable (see code below).
Also, since you're using sendAndLoad you should create another LoadVars object
to handle the errors and success values from the server.