1 Reply Latest reply on May 19, 2009 10:25 AM by starfighter10

    login issue flex/php

    starfighter10

      Hello,

       

      I found a working loginscreen with usern,pass and button. I want to extend it with a login admin. When he is logged in, there are extra panels visible then when a user is logged in.

       

      I've tried different things, first I'll give you the one that works WITHOUT the admin..

       

       

      <?php
      define( "DATABASE_SERVER", "**" );
      define( "DATABASE_USERNAME", "***" );
      define( "DATABASE_PASSWORD", "**" );
      define( "DATABASE_NAME", "*" );
      //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(!$result)
      {
      $output .= "no"; 
      }else{
      $output .= "yes";
      }
      $output .= "</loginsuccess>";
      //output all the XML
      print ($output);
      ?>

       

      flex code:

       

      private function checklogin(evt:ResultEvent):void

      {

      if(evt.result.loginsuccess == "yes")

      {

      _user = this.username.text;

      this.lblwelkom.text="Welkom " + _user;

      currentState = ""

      ;

      }

      if(evt.result.loginsuccess == "no")

      {

      mx.controls.Alert.show("Invalid username/password");

      }

      }

       

       

      THEN THE CODE I'VE TRIED TO INCLUDE THE ADMIN==>

      With wampserver I connect to database with fields username,password and admin. When a personis admin he has the word 'admin' in the admin column, when he's just a user the field is left blank.

      So I tried different things, first with creating a second query in the php file: I’ve put the added code in color!

       

       

       

       

       

      <?php

      define( "DATABASE_SERVER", "**" );
      define( "DATABASE_USERNAME", "***" );
      define( "DATABASE_PASSWORD", "**" );
      define( "DATABASE_NAME", "*" );

      //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' AND admin is null";

      $query2 = "SELECT * FROM users WHERE username = '$username' AND password = '$password' AND admin is not null";

      $result = mysql_fetch_array(mysql_query($query));

      $result2 = mysql_fetch_array(mysql_query($query2));

      $output = "<loginsuccess>";

      if($result)

      {

        $output .= "yes";

      }

      if($result2)

      {          

        $output .= "admin";

      }

      }

      else

      {

      $output .= "no";

      }

      $output .= "</loginsuccess>";

      //output all the XML

      print ($output);

      ?>

       

       

      private function checklogin(evt:ResultEvent):void

                                         {

                                                     if(evt.result.loginsuccess == "admin")

                                                     {

                                                                 this.pnlmonbeheer.visible=true;

                                                                 _user = this.username.text;

                                                                 this.lblwelkom.text="Welkom " + _user;

                                                                 currentState = "";

                                                     }

                                                     if(evt.result.loginsuccess == "yes")

                                                     {

                                                                 _user = this.username.text;

                                                                 this.lblwelkom.text="Welkom " + _user;

                                                                 currentState = "";

                                                     }

                                                     else(evt.result.loginsuccess == "no")

                                                     {

                                                                 mx.controls.Alert.show("Invalid username/password");

                                                     }                      

                                                    

                                         }

      I think I'm not using the right php code. Anyone?

      It would be really helpfull, thank thanks in advance

       

        • 1. Re: login issue flex/php
          starfighter10 Level 1

          Can anyone help me please?

           

          In short terms, I want to extend a working php script with an extra "admin" next to a "user". So there are two different sort of persons who can log in and so there will appear different panels. I think the working php, which I copied below, should have an extra query with an "admin is not null", so there will be another if statement with $output .= "admin";

           

          But somehow it doesn't seem to work, anyone?

           

          php code:

           

          $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(!$result)
          {
          $output .= "no"; 
          }else{
          $output .= "yes";
          }
          $output .= "</loginsuccess>";
          //output all the XML
          print ($output);
          ?>

           

          thanks in advance