4 Replies Latest reply on Sep 27, 2011 3:34 PM by Amy Blankenship

    Flex Login Issue - having to login twice...

    Jason Woodcock Level 1

      Alright, here's what I got...


      Very simple login for a flex app via php/mysql.


      Here my PHP (crude, for testing purposes):



      define( "DATABASE_SERVER", "*******" );
      define( "DATABASE_USERNAME", "*******" );
      define( "DATABASE_PASSWORD", "*******" );
      define( "DATABASE_NAME", "*******" );
      define( "DATABASE_USERTABLE", "*******" );
      //connect to the database
      $mysql = mysql_connect(DATABASE_SERVER, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error());
      //select the database
      mysql_select_db( DATABASE_NAME );
      //asign the data passed from Flex to variables
      $username = mysql_real_escape_string($_POST["username"]);
      $password = mysql_real_escape_string($_POST["password"]);
      //Query the database to see if the given username/password combination is valid.
      $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
      $result = mysql_fetch_array(mysql_query($query));
      //start outputting the XML
      $output = "<loginsuccess>";
      //if the query returned true, the output <loginsuccess>yes</loginsuccess> else output <loginsuccess>no</loginsuccess>
              $output .= "no";    
              $output .= "yes";    
      $output .= "</loginsuccess>";
      //output all the XML
      print ($output);


      This is called by my login page's function:



      protected function loginHandler(event:MouseEvent):void
                  userRequestResult.token = login.userRequest(usernameTextInput.text,passwordTextInput.text);
                  if(userRequestResult.lastResult == "yes") {
                      FlexGlobals.topLevelApplication.username = usernameTextInput.text;
                      FlexGlobals.topLevelApplication.password = passwordTextInput.text;
                 else if(userRequestResult.lastResult == "no"){
                      statusLabel.text = "Login incorrect! (Check username/password)";
                 else {
                      statusLabel.text = "Login Error! (Please check your network connection!)";


      I've tested my data service inside fles and it returns properly.


      Now, the first time I try to log in, it gives me the "Login Error!" message (whether it is correct or incorrect). However, the second time I hit enter or click login it logs me in properly or gives me the appropriate warning.


      I think the problem has to do with the fact that I am calling the .lastResult, but I can't figure out how to properly handle this.