1
votes

i'm still novice in AS3 Programming i was trying to get a login screen to work on my AIR Application, but i got error #2101 The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.

here's the code for processLogin

            public function processLogin():void {

                if(username.text != "" && password.text != "")
                {
                   var checkName = username.text
                   var checkPass = password.text
                   var resulttext = result_text.text

                   var request:URLRequest = new URLRequest("http://localhost/caservers/aksessistemlogin.php")
                   var loader:URLLoader = new URLLoader()    

                   var variables:URLVariables = new URLVariables()
                       variables.username = checkName            
                       variables.password = checkPass
                       variables.systemResult = resulttext
                   loader.dataFormat = URLLoaderDataFormat.VARIABLES
                   request.data = variables

                   request.method = URLRequestMethod.POST
                   loader.addEventListener(Event.COMPLETE, logincheck)
                   loader.load(request)

               }
               function logincheck (event:Event):void {

                  if (username.text == checkName && password.text == checkPass){
                     gotoAndPlay(2);
                  }else{
                     result_text.text = resulttext ;
                  }
               }
            }

and this one is the code for PHP

      <?php 
          include_once "connect.php";
          $username = $_POST['username'];
          $password = $_POST['password'];
          if ($_POST['systemCall'] == "checkLogin") {
              $sql = "SELECT * FROM users WHERE username='$username' AND password='$password'";
              $query = mysqli_query($sql);
              $login_counter = mysqli_num_rows($query);
              if ($login_counter > 0) {
              while ($data = mysqli_fetch_array($query)) {

              }
              } else {
                  $systemResult = "The login details don't match our records";
              }
          }
      ?>

what i'm intend to do is to check if the username and password is match with the one in the database, i followed some tutorials but it ended up advancing to next frame even without typing anything in the text input (just by clicking submit).

any help will be very very appreciated! thanks in advance..

1
You really need to learn how to use semicolons in AS3 - BadFeelingAboutThis
as i stated before, i'm a novice, well it made me confused since some tutorials put the semicolon and the others aren't.. - Chlova Aprian
That's ok, just take out this line: loader.dataFormat = URLLoaderDataFormat.VARIABLES - BadFeelingAboutThis
aah yes it works now! thanks a lot :D edit: put it as answer so i can select it :) - Chlova Aprian

1 Answers

0
votes

When you have this line in AS3:

loader.dataFormat = URLLoaderDataFormat.VARIABLES;

You are telling flash to decode the response from the loader as URL encoded variables. Your response however must not be that, because you get an error when it tries to decode the output of your PHP page as URL variables.

Flash will automatically know that you are sending URL encoded data when you assign a URLVariables object to the data property.