Hey all, been working on a flash based website that will have a login system.
I need for the flash interface to pass two variables to my PHP script (username and password). The PHP script will connect to my mySQL database and see if there there is a match, if so the PHP script will return a value to flash in order to allow access. Sounds pretty straightforward but as its my first attempt at all this i'm having some problems and hopefully the experts on this board might be able to give me a hand.
Ill try to explain everything as indepth as I can.
I have the mySQL database up and running and I've put together a php script that queries the database (ive tested the script by creating a html form and it works as expected by letting me know if the username and password is correct) however im not sure how the script should be altered for use by flash instead of html. the script so far is:
PHP Code:
<?php
//My login Script
// declare variables
$username=$_POST['uname'];
$password=$_POST['passw'];
//
// mysql connection variables
$host = '*****';
$dbuser = '*****';
$dbpass = '*****';
$dbname = '*****';
$table = '*****';
//
// connect to db
$db = @mysql_connect($host,$dbuser,$dbpass) or die("error=could not connect to $host");
$db = mysql_select_db($dbname);
if(!$db)
{
print "error=could not connect to $dbname table";
exit;
}
//
// check table
$query = mysql_query("SELECT * FROM $table WHERE USERname = '$username' AND USERpass = '$password'");
$num = mysql_num_rows($query);
if($num>0)
{
print "user=ok";
} else {
print "error=not ok";
}
?>
like I said this works fine with a html form and the variables sent through POST. I have two text fields declared in flash and a submit button, Ive created the following AS2 code for the login:
Code:
var submit:Button = Button(submitbtn);
var uname:TextField = TextField(uname);
var passw:TextField = TextField(passw);
var msgbox:TextField = TextField(msg);
//
submit.onRelease = function() {
//call php to verify the correct username and password
var myVars:LoadVars = new LoadVars();
myVars.uname = uname.text;
myVars.passw = passw.text;
myVars.sendAndLoad("login.php", myVars, 'POST');
myVars.onLoad = function(success) {
if (success) {
msgbox.text = "yup";
} else {
msgbox.text = "nope";
}
};
};
stop();
The error im getting is that the script constantly prints out "nope" to messagebox indicating its not loading the login.php script. Ive tried using full path names to the login script and the login script is in the same directory as the php file on the server.
Any help is muchly appreciated
Thanks in advance
Ant