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

flash data integration : loadVariables Command help


_Toe_
5/18/2005 12:00:00 AM
Hello,

I have a MYSQL database named "Users". I am trying to grab the fields "User"
and "Password" for use in a login script. (of course) I am unsure of the
syntax of the loadVariables command, and how to use it to grab the data from a
MYSQL database.

Thanks,
C
Randy1969
5/19/2005 4:31:31 PM
_Toe_
5/21/2005 12:00:00 AM
Ok, So the script in PHP would need to find and grab "User" and "Password"
fields from the database. What would the flash commanding look like?

LoadVariables "user" "password" from blah.php?

Thanks,
C
Joaquim Lopes
5/21/2005 12:00:00 AM
On the Flash side use this:

var dataToSend:LoadVars = new LoadVars();
var answer:LoadVars = new LoadVars();

dataToSend.username = username.text;
dataToSend.sendAndLoad("http://localhost/login.php", answer, "POST");

answer.onLoad = function(success)
{
if(success)
{
if(this.numElements == 1) // There can be only one user
with this name...
{
if(this.userPasword == userPasword.text)
{
// everything is good...
}
else
{
// user entered the wrong password...
}
}
}
}

On the PHP side:

<?php
$hostname = "localhost";
$database = "whatever";
$username = "username";
$password = "top secret";
$con = mysql_pconnect($hostname, $username, $password) or die(mysql_error());

mysql_select_db($database, $con);

$search = sprintf("select * from users where username = '%s'",
$_POST["username"]);
$data = mysql_query($search, $con) or die(mysql_error());
$line = mysql_fetch_assoc($data);
$num_lines = mysql_num_rows($data);
$result = "&numElements=" . $num_lines;
if($num_lines != 0)
{
$result .= sprintf("&name=%s&password=%s",
utf8_encode($line['username']),
utf8_encode($line['password']));
}
echo $result;
mysql_free_result($con);
?>

Hope this helps.
adireddy
5/23/2005 12:00:00 AM
AddThis Social Bookmark Button