Login page with PHP

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.   
  12. <body>  
  13. <form name="frm" id="frm" method="post" enctype="multipart/form-data">  
  14. <table border="1" cellpadding="2" cellspacing="5" align="center" width="100%">  
  15.   
  16. <tr>  
  17. <td>User Name</td>  
  18. <td><input type="text" name="txtUser" /></td>  
  19.   
  20. </tr>  
  21. <tr>  
  22. <td>Password</td>  
  23. <td><input type="password" name="txtPassword" /></td>  
  24. </tr>  
  25. <tr>  
  26. <td></td>  
  27. <td><input type="submit" name="btnSubmit" value="Login" /></td>  
  28. </tr>  
  29. </table>  
  30. <?php  
  31. if(isset($_POST['btnSubmit']))  
  32. {  
  33. echo $strQuery ="select User_Name, Password from TABLE NAME where User_Name='".$_POST['']."' && Password='".$_POST['Password']."'";  
  34.   
  35. echo $strRun =mysql_query($strQueryor die("error".mysql_error());  
  36. $count = mysql_num_rows($strRun);  
  37. if($count==1)  
  38. {  
  39. ?>  
  40. <script language="javascript">  
  41. window.location='fetch.php';  
  42. </script>  
  43. <?php  
  44. }  
  45. else  
  46. {  
  47. echo"invalid user name or password!!!";  
  48. }  
  49. }  
  50. ?>  
  51.   
  52. </form>  
  53. </body>  
  54. </html> 
Next Recommended Reading Create Master Page Template In PHP