Groups | Blog | Home
all groups > flash data integration > november 2005 >

flash data integration : Flash to MySQL database with PHP


marceldeboer
11/28/2005 12:00:00 AM
I hope someone can help me out here..... I have made a member form in flash and
want the result to be added in mySQL database. (First name, address, place,
etc.)

When all the fields are filled in and you click the send button it?s checking
the required fields, when OK the form is send to the addmemeber.php file.

Flash code below:
on (release) {
if (firstname eq "" | address eq "" | place eq "" ) {
result = "You must fill in all required fields";
} else {
result = "Your membership has been send";
loadVariablesNum("addmemeber.php", 0, "POST");
}
}

OK, the output has been send to the php file addmember.php
PHP code below:

<?php

//Database connection
$dbhost = "localhost"; // database host
$dbuser = "root"; // database user
$dbpass = ""; // database password
$dbname = "dbname"; // database name

//Connect
$open = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());


$firstname = $_POST["firstname"];
$address = $_POST["address"];
$place = $_POST["place"];

$query = mysql_query("INSERT INTO members (firstname, address, place)
VALUES ('$firstname', '$address', '$place')") or die (mysql_error());
?>

When I look into mySQL table nothing is added. :confused;
When I make a form in html/php with the same fields it's working. I can not
find out where I'm going wrong. Can someone help me out here.....

Masamune
11/28/2005 12:59:47 PM
Here is some Flash code that should work for you:
on(release){
if (firstname eq "" | address eq "" | place eq "" ) {
result = "You must fill in all required fields";
} else {
var myDataResponse:LoadVars = new LoadVars();
var myData:LoadVars = new LoadVars();
myData.firstname= firstname;
myData.address = address;
myData.place= place;
myData.sendAndLoad("addmember.php", myDataResponse, "POST");
myDataResponse.onLoad = function() {
if (this.result == "OK") {
result= "Your membership has been sent.";
} else {
result= this.result;
}
}
}
}

In your PHP file you could then put

"result=".mysql_error()

and at the end put

echo "result=OK";

This will catch any PHP errors for you.

Chris
marceldeboer
11/29/2005 12:00:00 AM
Chris,

Thank you for your reply and input. I'm working with your solution. I let you know if this is working.

marceldeboer
11/30/2005 10:24:06 AM
I have added the actionscript in flash and change the php file. When I click the send button I get the result Undefined.
Masamune
11/30/2005 1:24:23 PM
Try removing the quotation marks from the $_POST[variable] as in:

$firstname = $_POST[firstname];
$address = $_POST[address];
$place = $_POST[place];

If that doesn't work, you could send me your php and fla files and I can debug
them for you.

Chris
marceldeboer
12/1/2005 12:00:00 AM
Chris,

I really appreciate your cooperation with my project. I will try out your
solution and test it.
It?s no problem to send you the fla/php and sql file if your solution is not
working.

I let you know.....


Thanks Marcel

marceldeboer
12/1/2005 10:37:28 AM
Chris,

I have been trying your solution but still no result. I have send you een email with the files.


Masamune
12/1/2005 1:46:29 PM
Marcel,

I found why your movie wasn't working. You need to give an absolute path to
your php script in the sendAndLoad function.
Something like:
myData.sendAndLoad("http://localhost/menu/php/addmember.php", myDataResponse,
"POST");

For PHP, check your dbname to make sure it matches your mysql database name.

Add the following variable line:
$geslacht = $_POST[geslacht];

The error catching syntax is as follows:
... or die ("result=".mysql_error());

These changes got the movie working with PHP and MySQL. Let me know if you
have any problems.

Chris
marceldeboer
12/1/2005 2:57:27 PM
Chris,

I will test it and let you know.

AddThis Social Bookmark Button