Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2009
    Location
    Odense, Denmark
    Posts
    71
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Actionscript evaluation issue

    Hi guys,


    I'll make it short:

    I'm writing a login-system for my website. It checks for the appropriate username and password in my database via a php-script and returns "user=" and a value. The value it returns IS the rigth one - I just can't get flash to evaluate it. What I want is:

    if this.user is 0 then deny access (with a gotoAndStop(frame)) and if this.user > 0 then grant access.

    What's wrong with this validation?

    Code:
    on (release) 
    {
    	err_msg.text=''
    	if(userName.length > 0 &&  userPassword.length > 0)
    	{
    		var loginVars = new LoadVars();
    		loginVars.action = 'login';
    		loginVars.username = userName.text;
    		loginVars.pass = userPassword.text;
    		loginVars.sendAndLoad(php_file, loginVars, 'POST');
    		loginButton.enabled = false;
    		loginVars.onLoad = function() {
                if (!this.error) {
    				if (this.user > 0) {
    					err_msg.text='It works. User greater than 0 ' + this.user;
    				} else if (this.user == 0) {
    					err_msg.text='User = 0 ' + this.user;
    				} else {
    					err_msg.text='Somethings rotten ' + this.user;
    				}
    			}
    			else {
    				if(this.error != undefined) {
    					err_msg.text='error, but not undefined';
    				} else {
    					err_msg.text='error is undefined';
    					}
    			}
    			userName.selectable = true;
                userPassword.selectable = true;
                loginButton.enabled = true;
            }
    
    	}
    }
    No matter the value of this.user, the err_msg always writes "It works. User greater than 0" and then the value of this.user.
    As you can see, after each evaluation attempt I print the value of this.user. If I've inputted a wrong set of username and password, then this results in:
    "It works. User is greater than 0 0" (The zero being the value of this.user).
    Am I using the operators in the wrong way?


    Thanks in advance,
    deaf_digit

  • #2
    Regular Coder
    Join Date
    Nov 2009
    Location
    Scotland / Glasgow
    Posts
    184
    Thanks
    1
    Thanked 19 Times in 19 Posts
    php will return a string even though it's a number.
    check for a string instead of a number and you should be sorted.
    Code:
    if (this.user != "0") {
    	err_msg.text='It works. User greater than 0 ' + this.user;
    } else if (this.user == "0") {
    	err_msg.text='User = 0 ' + this.user;
    } else {
    	err_msg.text='Somethings rotten ' + this.user;
    }
    hope it helps


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •