1

this is my as3 code which is sending variables to php

var myData:URLVariables = new URLVariables();
myData.firstName = "Kirill";
myData.lastName = "Poletaev";

var myRequest:URLRequest = new URLRequest("test.php");

myRequest.data = myData;
myRequest.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;

try
{
loader.load(myRequest);
}
catch (error:Error)
{
trace('Error: unable to load the document.');
}

and this is my php code

<?php
$text=$_POST['firstName']." ".$_POST['lastName'];
$to="anubhavjhalani09@gmail.com";
$subject="Message from php";
mail($to,$subject,$text,"Content-Type: text/plain; charset=utf-8");
echo $text;
?>

my both fla and php files are in the same folder in the server.still when i execute php i m getting this error

Notice: Undefined index: firstName in C:\xampp\htdocs\flasblog\test.php on line 2

Notice: Undefined index: lastName in C:\xampp\htdocs\flasblog\test.php on line 2

somebody please help me

2
Contributors
8
Replies
10
Views
5 Years
Discussion Span
Last Post by aaloo
1

Try add the url to the URLRequest:

var myRequest:URLRequest = new URLRequest("http:/your_server/test.php");

bye.

0

sorry i didnt understand . what do u mean by "your_server" ??

Edited by aaloo: n/a

0

hey i got yoy but now i am getting this error

Error: Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
at Error$/throwError()
at flash.net::URLVariables/decode()
at flash.net::URLVariables()
at flash.net::URLLoader/onComplete()
how to solve it ?

1

According to adobe livedocs:

When you define variables within the URLVariables constructor or within the URLVariables.decode() method, you need to make sure that you URL-encode the ampersand character because it has a special meaning and acts as a delimiter. For example, when you pass an ampersand, you need to URL-encode the ampersand by changing it from & to %26 because the ampersand acts as a delimiter for parameters.

So if your link is something like this:

http://a_server/a directory/page.php&id=1

You have to change it to:

http://a_server/a%20directory/page.php%26id=1

You can easily use urlencode() to create those links: http://php.net/manual/en/function.urlencode.php
Hope is useful, bye :)

0

ok sir , i have solved the problem.but still when i execute my php file i m again getting this error


Notice: Undefined index: firstName in C:\xampp\htdocs\flasblog\test.php on line 3

Notice: Undefined index: lastName in C:\xampp\htdocs\flasblog\test.php on line 3

my php code is

<?php include_once"scripts/connect.php"; ?>
<?php
$text=$_POST['firstName']." ".$_POST['lastName'];
$to="anubhavjhalani09@gmail.com";
$subject="Message from php";



//data insert into database
$sql="INSERT INTO entries (contents)
VALUES
('$text')";

echo $text;
?>

and my as3 code is

var myData:URLVariables = new URLVariables();
myData.firstName = "Kirill";
myData.lastName = "Poletaev";

var myRequest:URLRequest = new URLRequest("http://localhost/flasblog/test.php");

myRequest.data = myData;
myRequest.method = URLRequestMethod.POST;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;

try
{
loader.load(myRequest);
}
catch (error:Error)
{
trace('Error: unable to load the document.');
}

please help me as soon as possible

Edited by aaloo: n/a

0

i think my php file is not getting variables from flash . is it ?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.