Login page with PHP

Before running this you have to install "PhpMyAdmin & server & mySql"or "wamp"or "xampp" in your pc. then open any browser and write in Url bar "Localhost/phpmyadmin" and here we make our Database,
Now open one more tab in browser and open "localhost/Filename". we all know the ip address of localhost is 127.0.0.1

  1. <?php
  2. mysql_connect("localhost","root","");
  3. mysql_select_db('database name');
  4. ?>
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  9. <title>My login</title>
  10. </head>
  11. <body>
  12. <form name="frm" id="frm" method="post" enctype="multipart/form-data">
  13. <table border="1" cellpadding="2" cellspacing="5" align="center" width="100%">
  14. <tr>
  15. <td>User Name</td>
  16. <td><input type="text" name="txtUser" /></td>
  17. </tr>
  18. <tr>
  19. <td>Password</td>
  20. <td><input type="password" name="txtPassword" /></td>
  21. </tr>
  22. <tr>
  23. <td></td>
  24. <td><input type="submit" name="btnSubmit" value="Login" /></td>
  25. </tr>
  26. </table>
  27. <?php
  28. if(isset($_POST['btnSubmit']))
  29. {
  30. echo $strQuery ="select User_Name, Password from TABLE NAME where User_Name='".$_POST['']."' && Password='".$_POST['Password']."'";
  31. echo $strRun =mysql_query($strQuery) or die("error".mysql_error());
  32. $count = mysql_num_rows($strRun);
  33. if($count==1)
  34. {
  35. ?>
  36. <script language="javascript">
  37. window.location='fetch.php';
  38. </script>
  39. <?php
  40. }
  41. else
  42. {
  43. echo"invalid user name or password!!!";
  44. }
  45. }
  46. ?>
  47. </form>
  48. </body>
  49. </html>