AS3 PHP mysql login and session
Hi,
Im trying to create a simple login for my website www.canyon.tv . Im able to get the code to login to the mysql database in the php script, but when I try to redirect to another page on a successful load, the function does nothing.
My flash code looks like this:
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLRequestMethod;
logbtn.addEventListener(MouseEvent.CLICK, login)
function login($e:MouseEvent){
var myVariables:URLVariables = new URLVariables();
var myRequest:URLRequest = new URLRequest("login.php");
myRequest.method = URLRequestMethod.POST;
myRequest.data = myVariables;
var myLoader:URLLoader = new URLLoader;
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.addEventListener(Event.COMPLETE, completeHandler);
myVariables.user = loguser.text;
myVariables.pass = logpass.text;
myLoader.load(myRequest);
getURL("http://www.canyon.tv/index.html");
function completeHandler(event:Event):void{
trace(event.target.data.user);
trace(event.target.data.pass);
trace(event.target.data.err);
getURL(http://www.canyon.tv/error.html);
}
}
my php looks like this:
<?php
//Connect To Database
$hostname="hostname"
$username="username";
$password="password";
$dbname="dbname";
$tableName="users";
$yourfield = "your_field";
mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
mysql_select_db($dbname);
foreach ($_POST as $key => $value) {
$$key = $value;
$$key = mysql_real_escape_string($$key);
}
$result = mysql_query("SELECT * FROM " .$tableName. " WHERE username = '" .$username. "' AND password = '" .$password. "'") or die(mysql_error());
$echoS = "false";
while($row = mysql_fetch_array($result)){
$echoS ="true";
}
echo "login=".$echoS;
mysql_close();
?>
Im still working on maintaining the session variables. Please can you help me see where I am going wrong?
Thanks in advance
Warren
