By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

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

P: 13
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 ....

Sep 18 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 1,584
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?

Sep 18 '08 #2

P: 40
Hi shwetha,
First you must send all the values from the registration form to the database and try out the below code...
Expand|Select|Wrap|Line Numbers
  1. <?php
  3. if(isset($_POST['<submit button name>']))
  4. {
  6.        $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>]'");
  8. $row=mysql_num_rows($result);
  10. if($row>0)
  11. {
  12.     header('location:<specifipage>.php');
  13. }
  14. else
  15. {
  16.     alert(Incorrect username and password);
  17. }
  18. }
  19. ?>
Hope this works....
Sep 18 '08 #3

Expert 5K+
P: 6,050
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.
Sep 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.