How to check whether the username and password entered in a login php form are valid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shwethatj
    New Member
    • Sep 2008
    • 13

    How to check whether the username and password entered in a login php form are valid

    Could anyone please tel me in detail ... How to check whether the username and password entered by user in a login php form are valid ... I have not created any database ...

    I already have created a registration form , in which user enters his details ... But how can i make sure that in login form, he enters the same id and password ....

    Regards,
    Shwetha
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    you get the the record in the database for the username he's giving you, if any exist.

    Then get the stored password and compare it to the one he entered. If they are the same, he's validated.

    Are you talking about some other validation?



    Dan

    Comment

    • divyac
      New Member
      • Aug 2008
      • 40

      #3
      Hi shwetha,
      First you must send all the values from the registration form to the database and try out the below code...
      Code:
      <?php
      
      if(isset($_POST['<submit button name>']))
      {
      
             $result=mysql_query("SELECT * FROM tablename WHERE <name field from database>='$_POST[<textbox name of name>]' and <password field from database>='$_POST[<textbox name of password>]'");
      
      $row=mysql_num_rows($result);
      
      if($row>0)
      {
      	header('location:<specifipage>.php');
      }
      else
      {
      	alert(Incorrect username and password);
      }
      }
      ?>
      Hope this works....

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        First of all you're going to have to create a database table. You could use flat files... but that's more effort than what's required.

        Comment

        Working...