Ask a Question related to Macromedia Flash Data Integration, Design and Development.
-
connoru #1
sendandload to php problem
I thought this should be relatively straightforward but ....
I want to send two variables from a swf to a php script.
The php script then inserts them into a table row in a mySQL database.
I can do this with the loadVars send() function. I have this working. However,
this opens a new browser window.
I want the php script to run in the background (i.e. no new window).
I have tried the sendandload() function with various combinations of GET's and
POST's but no joy.
It is sending the variablesand the load returns success but I'm not getting
updates in the table.
It seems that the php script is not running? I'm fairly new to php. Does it
need to be in a browser to execute?
Heres the code
//AS
_global.sendNames = function(First, Last) {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace("LOAD Success");
trace(result_lv.PHPresult);
} else {
trace("LOAD Fail");
trace(result_lv.PHPresult);
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.firstName = First;
send_lv.lastName = Last;
trace("SENDING NAMES");
trace(First);
trace(Last);
send_lv.sendAndLoad("http://localhost/experiment/usersUpdate.php",
result_lv, "POST");
}
//PHP
<?
$host = "localhost";
$user = "root";
$pass = "28phaedruS";
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$db="results";
$link = mysql_connect($host, $user, $pass);
if (! $link)
$PHPresult="Couldn't connect to MySQL";
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query ("INSERT INTO users(firstName,lastName) VALUES
('$firstName','$lastName')");
echo("firstName=".$firstName."<br />");
echo("lastName=".$lastName."<br />");
mysql_close($link);
?>
Any Ideas?
connoru Guest
-
sendAndLoad()
attached is an xml very simple script in flash swf - however i do not know how to write the server side .asp can someone tell me what should be the... -
XML sendAndLoad problem
I have a simple sendAndLoad XML request that works perfectly on 95% of the computers I have used. I have check crosssite stuff and everything i can... -
https:// problem with sendandload
:confused; I am having a problem with sendAndLoad on a secure site. Has anyone run across this before? In Internet Explorer it does not work at... -
Need php help using xml sendandload
info: var bc_xml:XML = new XML(email); var email:String = "<email>ck1mark@hotmail.com</email>"; bc_xml.sendAndLoad(bc_url, bc_xml, "POST"); how... -
asp and sendAndLoad
I have a small app that sends and loads varsbetween flash and asp. I have a text field that allows the user to add new records to a DB. On the same... -
Motion Maker #2
Re: sendandload to php problem
1. Only PHP in the file. No html in other words.
2. No whitespace (sp cr tab) before the first php tag <?php or after the
last php tag ?>
3. echo back URL encoded variable pairs
var1=value&var2=value&var3=value:
echo "firstName=" . $firstName;
echo "&lastName=" . $lastName;
4. If you are using just the loadVars send method, then the PHP should not
echo any values back. Otherwise you need to use the sendAndLoad method and
send back URL encoded variable pairs.
5. You really do not want to use die and other PHP functions that result in
sending text. Rather build PHP code that captures the errors and if needed
return URL vars back to Flash for UI feedback.
echo "&success=" . $success ; // figured elsewhere
echo "&returnMessage=" . "Couldn't open $db: " . mysql_error() ; // If you
need to see in Flash for debugging
Here is a basic send and return with loadVars and PHP I use in training
courses.
[url]http://www.hosfordusa.com/ClickSystems/courses/flash/examples/LoadVars/Ex01/LoadVarsEx01.php[/url]
--
Lon Hosford
[url]www.lonhosford.com[/url]
May many happy bits flow your way!
"connoru" <webforumsuser@macromedia.com> wrote in message
news:dns17k$q35$1@forums.macromedia.com...
I thought this should be relatively straightforward but ....
I want to send two variables from a swf to a php script.
The php script then inserts them into a table row in a mySQL database.
I can do this with the loadVars send() function. I have this working.
However,
this opens a new browser window.
I want the php script to run in the background (i.e. no new window).
I have tried the sendandload() function with various combinations of GET's
and
POST's but no joy.
It is sending the variablesand the load returns success but I'm not getting
updates in the table.
It seems that the php script is not running? I'm fairly new to php. Does it
need to be in a browser to execute?
Heres the code
//AS
_global.sendNames = function(First, Last) {
var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
trace("LOAD Success");
trace(result_lv.PHPresult);
} else {
trace("LOAD Fail");
trace(result_lv.PHPresult);
}
};
var send_lv:LoadVars = new LoadVars();
send_lv.firstName = First;
send_lv.lastName = Last;
trace("SENDING NAMES");
trace(First);
trace(Last);
send_lv.sendAndLoad("http://localhost/experiment/usersUpdate.php",
result_lv, "POST");
}
//PHP
<?
$host = "localhost";
$user = "root";
$pass = "28phaedruS";
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$db="results";
$link = mysql_connect($host, $user, $pass);
if (! $link)
$PHPresult="Couldn't connect to MySQL";
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query ("INSERT INTO users(firstName,lastName) VALUES
('$firstName','$lastName')");
echo("firstName=".$firstName."<br />");
echo("lastName=".$lastName."<br />");
mysql_close($link);
?>
Any Ideas?
Motion Maker Guest
-
flash-hero #3
Re: sendandload to php problem
you can't send using POST from Flash and then read with $_GET in PHP. You must of course read from $_POST["firstName"]
flash-hero Guest
-
Samad #4
Re: sendandload to php problem
Hi, did you success in making php handle and store data in background? if so could you please give me a shot?
ThanksSamad Guest



Reply With Quote

