Advertisement
Guest User

Untitled

a guest
May 30th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2. session_start();
  3. require('config.php');
  4.  
  5. if($_POST['submit'])
  6. {
  7. $query="select * from tb_user where user_name='".addslashes($_POST['username'])."' and password='".addslashes($_POST['password'])."'";
  8. $login=mysql_query($query);
  9. if(mysql_num_rows($login)>0)
  10. {
  11. $userData=mysql_fetch_object($login);
  12. $_SESSION['userid']=$userData->id;
  13. $_SESSION['deptid']=$userData->dept_id;
  14. $_SESSION['usertype']=$userData->user_type;
  15. header("Location: index.php");
  16. }
  17. else
  18. {
  19. header("Location: login.php?msg=error");
  20. }
  21. }
  22.  
  23. ?>
  24. <?php
  25. if($_GET['msg'])
  26. {
  27. echo '<span style="color:red">Invalid username or password</span>';
  28. }
  29. ?>
  30.  
  31. <form method="post" onSubmit="return validate()">
  32. Username:<input type="text" name="username" value="" id="username"></input><div class=error id=nameError style="display:none">Enter Username</div><br>
  33. Password:<input type="password" name="password" value="" id="password"></input><div class=error id=passError style="display:none">Enter Password</div><br>
  34. <input type="submit" value="Login" name="submit"></input>
  35.  
  36. </form>
  37. <?php
  38.  
  39. ?>
  40. <script type="text/javascript">
  41. function validate()
  42. {
  43. uname=document.getElementById("username").value
  44. password=document.getElementById("password").value
  45. hideallerrors();
  46. if(uname=="")
  47. {
  48. document.getElementById("nameError").style.color="red";
  49. document.getElementById("nameError").style.display = "inline";
  50. document.getElementById("username").select();
  51. document.getElementById("username").focus();
  52. return false;
  53. }
  54. else if(password=="")
  55. {
  56.  
  57. document.getElementById("passError").style.color="red";
  58. document.getElementById("passError").style.display = "inline";
  59. document.getElementById("password").select();
  60. document.getElementById("password").focus();
  61. return false;
  62. }
  63. else
  64. {
  65. return true;
  66. }
  67. }
  68. function hideallerrors()
  69. {
  70. document.getElementById("nameError").style.display = "none";
  71. document.getElementById("passError").style.display = "none";
  72.  
  73. }
  74. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement