this article was taken from the following url:
http://www.sephiroth.it/tutorials/flashPHP/loadVars/page02.php i 've not yet tested it.. will go through it tomorrow morning when i get back
to the work. i hope it will work out.
send() method
Description:
send is used when you want to send some variables to an external page. It
automatically converts the property of the LoadVars object into a url-encoded
string
Returns:
Return always a true value, if the LoadVars object has at least one property
to send, otherwise it returns false
Usage:
If we have a php page with a mysql query which expects nome, nickname and
email as external variables:
<?php
if(!empty($_POST['nome']) && !empty($_POST['nick']) && !empty($_POST['mail']))
{
$conn = mysql_connect('host', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('db_name', $conn) or die (mysql_error());
$nome = $_POST['nome'];
$nick = $_POST['nick'];
$mail = $_POST['mail'];
$result = mysql_query("INSERT INTO nome_tabelle (nome, nick, mail)
VALUES ('$nome', '$nick', '$mail')") or die(mysql_error());
if($result)
{
echo "Everything is ok";
} else {
echo "Error writing data";
}
mysql_close($conn);
}
?>
In flash: first create a new instance of the LoadVars object, then assign to
it all the properties to pass, and finally call the send method.
myVars = new LoadVars();
myVars.nome = "pietro";
myVars.nick = "lana";
myVars.mail = "pietro@flash-php.it";
myVars.send("http://localhost/pagina.php", "_blank", "POST");
the argument "_blank" tell flash in which target open the destination page
"pagina.php". _blank means that a new page will be opened.
In the php page the variables are readed from the superglobal array $_POST, so
we need to pass the variables using the method "POST", which is the 3rd
argument passed n the send method.
5. sendAndLoad()
Description:
sendandLoad method combine the functionality of the methods load() and send(),
it parse the properties of the LoadVars object in url-encode strings and send
all to the external page, and will read the result output which this page send
back as response.
We can specify which LoadVars object has to receive response. In most cases,
use the same instance both for send and read data.
yVars = new LoadVars();
myVars.SendAndLoad(" http://percorso/pagina.php ", myVars, " POST ");
the arguments: page url, receiver object, sending method
Returns:
the same as the send method.
Usage:
For this example we will authenticate a user which send his login name and
password from flash
This is the php page which check the login and password reading a db:
<?php
if(!empty($_POST['nick']) && !empty($_POST['password']))
{
$conn = mysql_connect('host', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('db_name', $conn) or die (mysql_error());
$nick = $_POST['nick'];
$pass = $_POST['password'];
$result = mysql_query("SELECT * FROM tabella_utenti
WHERE nick= '$nick' AND password = '$pass'") or
die(mysql_error());
$num = mysql_num_rows($result);
if(num >0 )
{
echo "login=true&";
echo "msg=you're logged now";
} else {
echo "login=false&";
echo "msg=wrong user name or password";
}
mysql_close($conn);
} else {
echo "login=false&";
echo "msg=missing data";
}
?>
and in the same level a button with this code:
on(release){
myVars = new LoadVars();
myVars.nick = nickname.text;
myVars.password = password.text;
myVars.onLoad = function(success){
if(success){
trace(this.msg);
if(this.login){
// ok, you're logged.. go to the page for
// registered users
}
} else {
trace("Error reading the php page");
}
}
myVars.SendAndLoad("http://percorso/pagina.php", myVars, "POST");
}
send() method
Description:
send is used when you want to send some variables to an external page. It
automatically converts the property of the LoadVars object into a url-encoded
string
Returns:
Return always a true value, if the LoadVars object has at least one property
to send, otherwise it returns false
Usage:
If we have a php page with a mysql query which expects nome, nickname and
email as external variables:
<?php
if(!empty($_POST['nome']) && !empty($_POST['nick']) && !empty($_POST['mail']))
{
$conn = mysql_connect('host', 'user', 'pass') or die(mysql_error());
$db = mysql_select_db('db_name', $conn) or die (mysql_error());
$nome = $_POST['nome'];
$nick = $_POST['nick'];
$mail = $_POST['mail'];
$result = mysql_query("INSERT INTO nome_tabelle (nome, nick, mail)
VALUES ('$nome', '$nick', '$mail')") or die(mysql_error());
if($result)
{
echo "Everything is ok";
} else {
echo "Error writing data";
}
mysql_close($conn);
}
?>
In flash: first create a new instance of the LoadVars object, then assign to
it all the properties to pass, and finally call the send method.
myVars = new LoadVars();
myVars.nome = "pietro";
myVars.nick = "lana";
myVars.mail = "pietro@flash-php.it";
myVars.send("http://localhost/pagina.php", "_blank", "POST");
the argument "_blank" tell flash in which target open the destination page
"pagina.php". _blank means that a new page will be opened.
In the php page the variables are readed from the superglobal array $_POST, so
we need to pass the variables using the method "POST", which is the 3rd
argument passed n the send method.
5. sendAndLoad()
Description:
sendandLoad method combine the functionality of the methods load() and send(),
it parse the properties of the LoadVars object in url-encode strings and send
all to the external page, and will read the result output which this page send
back as response.
We can specify which LoadVars object has to receive response. In most cases,
use the same instance both for send and read data.
yVars = new LoadVars();
myVars.SendAndLoad(" http://percorso/pagina.php ", myVars, " POST ");
the arguments: page url, receiver object, sending method
Returns:
the same as the send method.
Usage:
For this example we will authenticate a user which send his login name and
password from flash
This is the php page which check the login and password reading a db:
<?php
if(!empty($_POST['nick']) && !empty($_POST['password']))