[F8]IF statement not working correctly ?
Hi guys im not sure whats going on here??
But the basics users clicks register it sends information to PHP page , PHP page returns a value either OK or RegError and depending on the retrieved value output a message.I have been rattling my brains for the past 3 hours trying to see where the problem is but for the life of me i cant see it :S
NOTE : I have block commented the functions in the hope it will help some people read the sections in the code.
Sorry for the long posts here guys but i thought i should post all my AS code for you guys to check.
BTW crms.no-ip.info is a locally hosted domain , So if my computer isnt on you wont be able to access that address, Just thought i should let you guys know.
Here is the AS code
Code:
stop();
_global.LoginScript;
_global.LoginScript = "http://crms.no-ip.info/flash/functions/login.php";
loginTxt.text = "";
///////////LOGIN SCRIPT CURRENTLY WORKING///////////////////////////////////
varReceiver = new LoadVars();
var AttemptCounter:Number = 0;
myBtn_btn.onRelease = function() {
ConnectionInfo.addItem("Attempting Login");
varReceiver.Age = age.selectedIndex+1;
varReceiver.Action = "ProcessLogin";
varReceiver.Username = username.text;
varReceiver.Userpassword = userpass.text;
varReceiver.sendAndLoad(_global.LoginScript,varReceiver,"POST");
loginTxt.text = "Processing Variables";
varReceiver.onLoad = function(){
//errormsg.text = this.login;
myTrace.text = unescape(this);
_global.UserCheck;
_global.UserCheck= this.login;
ConnectionInfo.addItem("Login Authorisation is : "+this.login);
AttemptCounter++;
LoginAttempts.text = "Logins Attempted "+AttemptCounter;
if(this.login == "YES"){
gotoAndPlay(10);
}else{
username.text = "";
userpass.text = "";
loginTxt.text = ("Your details could not be found, " +newline+ " Please either register yourself or " +newline+ "choose forgotten password.");
}
}
}
///////END LOGIN SCRIPT///////////////////////
///START NEW USER REGISTRATION CURRENTLY NOT WORKING PROPERLY//////////////////
varNewUser = new LoadVars();
register.onRelease = function() {
ConnectionInfo.addItem("Sending Registration Request");
varNewUser.Action = "ProcessRegister";
varNewUser.Username = username.text;
varNewUser.Userpassword = userpass.text;
varNewUser.sendAndLoad(_global.LoginScript,varNewUser,"POST");
//trace(varNewUser);
//getURL(_global.LoginScript);
varNewUser.onLoad = function(){
ConnectionInfo.addItem("Received response from Server");
ConnectionInfo.addItem ("Server Responded: "+this.newusers);
if(this.newusers == "OK"){
username.text = "";
userpass.text = "";
loginTxt.text = ("Registration Success"+newline+"Please proceed to login.");
}else{
trace("Entered Error");
trace("Value returned by server is "+this.newusers);
username.text = "";
userpass.text = "";
loginTxt.text = ("We were unable to process your registration this time");
}
}//End OnLoad function
}//end onRelease of register
//END NEW USER REGISTRATION/////////////////////////////////
The PHP code :
PHP Code:
$Username = ucfirst($_POST['Username']);
$Userpassword = md5($_POST['Userpassword']);
$Action = $_POST['Action'];
$login = "";
//What is the user trying to do ?
switch($Action){
case "ProcessLogin":
//Search for user in DB
$sql = ("SELECT * FROM `users` WHERE `Username` = '".$Username."' AND `Userspassword` = '".$Userpassword."'");
$query = mysql_query($sql);
$result = mysql_fetch_array($query);
if($result == ""){
$login = "NO";
echo ("&login=$login");
}else{
//write back to flash YES user is registered
$login = "YES";
echo ("&login=$login&");
///////
}
//
break;
case "ProcessRegister":
$sql = "INSERT INTO `users` (`Username`,`UsersPassword`) VALUES ('".$Username."', '".$Userpassword."')";
echo "The value of SQL is <br>".$sql."<br> END SQL <br>";
$query = mysql_query($sql);
if (!$query){
$login = "RegError";
echo ("&newusers=$login");
}else{
$login = "OK";
echo ("&newusers=$login");
}
break;
}
Now as you can see the PHP contains a switch to find out what the user wants to do either login or register and perform the relevant switch statement
Now what is puzzling me is that the this.newusers is always ok , I mean it inserts new data into the database but it doesnt display the ok message always says we cant process your registration in the flash window even though the insert worked fine :S Even when i "trace" this.newusers into the connection info listbox control it says Server Responded : OK So why is flash completely ignoring that and displaying the error message instead ?
The problem code i believe is this
Code:
if(this.newusers == "OK"){
username.text = "";
userpass.text = "";
loginTxt.text = ("Registration Success"+newline+"Please proceed to login.");
}else{
trace("Entered Error");
trace("Value returned by server is "+this.newusers);
username.text = "";
userpass.text = "";
loginTxt.text = ("We were unable to process your registration this time");
}
Once this is fully working i will comment it out and upload it as a Zip file in the tutorials section as a help me for people new to flash like myself. In the hope that others can benefit from it , Just need to get it working properly first lol.
Sorry for the epic post again guys and a BIG thank you for who ever takes the time out to read it.