8 Replies Latest reply on Jun 29, 2010 1:20 AM by djh88ukwb

    AFMPHP log in, not working =[

    djh88ukwb Level 1

      Hello all,

       

      I am using AMFPHP to create a log in.

       

      My PHP is as follows

       

      function getUser()
      {
      $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);
      mysql_select_db( $this->db_name);
      $code_entities_match = array('--','"','!','@','#','$','%','^','&','*','(',')','_','+','{','}','|',':','"','<','> ','?','[',']','\\',';',"'",',','.','/','*','+','~','`','=');
      $user = str_replace($code_entities_match, "", $User);
      $pass = str_replace($code_entities_match, "", $UserPass);
      $Query = "SELECT * FROM usernames WHERE username = '$user' AND password = '$pass'";
      $Result = mysql_query( $Query );
      return($Result);
      }

       

      Then my flex code

       

                  protected function application2_creationCompleteHandler():void           
                  {               
                      db_services.getOperation("getUser").send(usernameLogin.text,passwordLogin.text);
                  }

      <mx:method name="getYourCandidates" result="qrygetYourCandidates(event)"/>

                  protected function qryUserConfig(event:ResultEvent):void
                  {
                      if (event.result != null)
                      {
                          currentState="ok" ;               
                      }
                      else
                          Alert.show("Please consult an account admin.", "Login failed");
                  }

       

      Although i get no Flex errors, when i run the program, i can log in with details that are not in the database, it dosent actually query the database .


      Any reason why ?

        • 1. Re: AFMPHP log in, not working =[
          David_F57 Level 5

          hi,

           

          I sent you an email with the reasons that your login was failing(my mistake) 

           

                      protected function qryUserConfig(event:ResultEvent):void
                      {
                          if (event.result.length > 0)
                          {
                              currentState="ok" ;   

                              username = event.result[0].username .....etc....                
                          }
                          else
                              Alert.show("Please consult an account admin.", "Login failed");
                      }

           

          debug would have shown that it was actually an arraycollection being returned,  I confused my earlier response with zend/DCD lastresult.

           

          David.

          • 2. Re: AFMPHP log in, not working =[
            djh88ukwb Level 1

            Hey, sorry about this =[

             

            But it is not letting anyone log in now :S

             

            My php code is as

             

            function getUser()

            {

            $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

            mysql_select_db( $this->db_name);

            $code_entities_match =

            array('--','"','!','@','#','$','%','^','&','','(',')','_','+','{','}','|',':','"','<','>','?','[',']','
            ',';',"'",',','.','/','
            ','+','~','`','=');

            $user = str_replace($code_entities_match, "", $User);

            $pass = str_replace($code_entities_match, "", $UserPass);

            $Query = "SELECT * FROM usernames WHERE username = '$user' AND password =

            '$pass'";

            $Result = mysql_query( $Query );

            return($Result);

            }

             

            Flex code is

             

                        protected function qryUserConfig(event:ResultEvent):void

                        {

                            if (event.result.length > 0)

                            {

                                currentState= "clientadmin" ;

                            }

                            else

                                Alert.show("Please consult an account admin.", "Login

            failed");

                        }

             

                        protected function application2_creationCompleteHandler():void

                        {

             

            db_services.getOperation("getUser").send(usernameLogin.text,passwordLogin.text);

                        }

             

                        <mx:method name="getYourCandidates"

            result="qrygetYourCandidates(event)"/>

             

            Am i missing something ?

            • 3. Re: AFMPHP log in, not working =[
              David_F57 Level 5

              hi,

               

              What happened to you functions parameters ?, I removed the redundant stuff you don't need to test for all those erroneous characters

               

              function getUser($user,$pass)  <==== the parameters where missing

              {

              $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

              mysql_select_db( $this->db_name);

              $Query = "SELECT * FROM usernames WHERE username = '$user' AND password ='$pass'";

              $Result = mysql_query( $Query );

              return($Result);

              }

              1 person found this helpful
              • 4. Re: AFMPHP log in, not working =[
                djh88ukwb Level 1

                Ahh ! ! thanks, i didnt get them bits down yesterday =[

                 

                Cheers fella.

                 


                One last thing !

                 

                With my last log in, i was returning "level" as xml format, and using this script

                 

                            private function loginResult(evt:ResultEvent):void
                            {

                                 if (evt.result.status == true && evt.result.level == 'customer')
                                {
                                    currentState='customer';
                                    welcomenamecustomer.text = "Welcome " + evt.result.firstname + " " + evt.result.secondname;
                                    welcomenamecustomerref.text = "Ref No. " + evt.result.ref;
                                } 
                                else if (evt.result.status == true && evt.result.level == 'clientadmin')
                                {
                                    currentState='clientadmin';
                                    welcomenameadmin.text = "Welcome " + evt.result.firstname;
                                }
                                else if (evt.result.status == true && evt.result.level == 'clientuser')
                                {
                                    currentState='clientuser';   
                                    welcomenameuser.text = "Welcome " + evt.result.firstname + " " + evt.result.secondname;
                                    welcomenameuserref.text = "Ref No. " + evt.result.ref;
                                }
                                else
                                {
                                    Alert.show("Please consult an account admin.", "Login failed");
                                }
                            }

                 

                This was putting people to a different state depending upon that level value, which was from the database.  How would i do this using your log in ?

                • 5. Re: AFMPHP log in, not working =[
                  David_F57 Level 5

                  hi,

                   

                  pretty much the same as you did with xml

                   

                   

                  if (event.result[0].status == 'true' && event.result[0].level == 'customer')

                  {

                  ...........do some stuff

                  }

                   

                  I'm making the assumption that status and level are fields in your user record.

                   

                   

                  David.

                  • 6. Re: AFMPHP log in, not working =[
                    djh88ukwb Level 1

                    Hey David,

                     

                    Sorry, i have hit another snag.

                     

                    I was using a HTTPService and a single PHP script to add a record into the

                    database,  but i want to intergrate this in the AMFPHP file now.

                     

                    This is what i have so far.

                     

                    function addCandidate($firstname,$secondname,$username,$password)

                    {

                    $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

                    mysql_select_db( $this->db_name);

                    $sql = "INSERT INTO usernames (username, password, level, firstname,

                    secondname, assignedrecruiter)

                    VALUES('$username','$password','candidate','$firstname','$secondname','7')";

                    $Result = mysql_query( $Query );

                    return($Result);

                    }

                     

                                protected function

                    application3_creationCompleteHandler():void

                                {

                     

                    db_services.getOperation("addCandidate").send(createCandidateFirstName.text,createCandidat eSecondName.text,createCandidateUsername.text,createCandidatePassword.text);

                                }

                     

                    It dosent seem to add the record thou,  any ideas why ?

                     

                    Thanks Man ! !

                    • 7. Re: AFMPHP log in, not working =[
                      David_F57 Level 5

                      hi,

                       

                      of the top of my head, i would say you have a non null field such as an auto incrementing ID that wasn't included with your  insert statement, even if ID is autoincrementing you need to include it in your insert statement (usually just a O as its overridden anyway).

                       

                      You should get an error message back in your result if the record wasn't created and this will hopefully tell you why.

                       

                       

                      David.

                      • 8. Re: AFMPHP log in, not working =[
                        djh88ukwb Level 1

                        Hey David,

                        Thanks for this