Guest User

Untitled

a guest
Feb 3rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <style>
  6. body {
  7. width:400px;
  8. height:auto;
  9. margin: 0 auto;
  10. padding-top:20px;
  11. }
  12. body a {
  13. text-decoration:none;
  14. color:#0099CC;
  15. }
  16. .border{
  17. border:#999999;
  18. border-style:solid;
  19. border-width:thin;
  20. }
  21. </style>
  22. <?php
  23. include('connect.php');
  24. ?>
  25. <table width="350" class="border" >
  26. <form id="form1" name="form1" method="post" action="login.php" onSubmit="return validate()">
  27. <tr>
  28. <td width="112">&nbsp;</td>
  29. <td colspan="2"> <strong>Login</strong></td>
  30. <td width="22">&nbsp;</td>
  31. </tr>
  32. <tr>
  33. <td height="35">
  34. <div align="right">User Name : </div>
  35. </td>
  36. <td colspan="2"><label>
  37. <input type="text" name="name" id="name" /></label>
  38. </td>
  39. <td>&nbsp;</td>
  40. </tr>
  41. <tr>
  42. <td>
  43. <div align="right">Password : </div>
  44. </td>
  45. <td colspan="2"><input type="password" name="password" id="password" /></td>
  46. <td>&nbsp;</td>
  47. </tr>
  48. <tr>
  49. <td>
  50. <div align="right">select your role : </div>
  51. </td>
  52. <td colspan="2">
  53. <!-- <input type="radio" checked="checked" name="title" value="member" id="member" /> member</label>
  54. <label for="admin"> <input type="radio" name="title" value="admin" id="admin" /> admin</label> -->
  55. <label>
  56. <select name="member" id="member">
  57. <option title="title" value="member"> member
  58. <option title="title" value="admin"> admin
  59. </select>
  60. </label>
  61. </td>
  62. <td>&nbsp;</td>
  63. </tr>
  64. <tr>
  65. <td>&nbsp;</td>
  66. <td width="69"><label>
  67. <input type="submit" name="Submit" value="Login" id="add" /></label>
  68. </td>
  69. <td width="127"><label>
  70. <input type="reset" name="reset" value="reset" /></label>
  71. </td>
  72. <td>&nbsp;</td>
  73. </tr>
  74. <tr>
  75. <td>&nbsp;</td>
  76. <td><a href="register.php">Register ?</a> </td>
  77. <td><a href="forget_password.php">Forget Password?</a> </td>
  78. <td>&nbsp;</td>
  79. </tr>
  80. </form>
  81. </table>
  82. <script>
  83. function validate()
  84. {
  85. if( document.form1.name.value == "" )
  86. {
  87. alert( "Please provide your name!" );
  88. document.form1.name.focus() ;
  89. return false;
  90. }
  91. if( document.form1.password.value == "" )
  92. {
  93. alert( "Please provide your password!" );
  94. document.form1.password.focus() ;
  95. return false;
  96. }
  97. }
  98. </script>
  99. </body>
  100. </html>
  101.  
  102. <?php
  103. session_start();
  104. include('connect.php');
  105. $name = $_POST['name'];
  106. $password = $_POST['password'];
  107. $role = $_POST['member'];
  108. $sql = "select * from login_register where name = '$name'
  109. and password = '$password' and role = '$role'";
  110. $retain = mysql_query($sql, $con);
  111. // Mysql_num_row is counting table row
  112. $count=mysql_num_rows($retain);
  113. $row=mysql_fetch_array($retain);
  114.  
  115. if($count == 1)
  116. {
  117. if ( $role == "admin")
  118. {
  119. $_SESSION['adminuser']=$_POST['name'];
  120. header("location:admin_home.php");
  121. }
  122. else if ( $role == "member")
  123. {
  124. header("location:member_home.php");
  125. $_SESSION['user']=$_POST['name'];
  126. }
  127. }
  128. else
  129. {
  130. echo "<a href='index.php'>click here to login </a>";
  131. }
  132. ?>
  133.  
  134. $.ajax({
  135. type : "POST",
  136. data : { username: "user name", password: "user password", role:"your role" },
  137. url : 'some.php',
  138. dataType: 'json',
  139. success : function(response) {
  140. console.log( "response data: " + response );
  141. }
  142. });
  143.  
  144. <?php
  145. session_start();
  146. include('connect.php');
  147.  
  148.  
  149. if(isset($_POST['name']))
  150. {
  151. $sql = "select * from login_register where name = ".$_POST['name'];
  152. $retain = mysql_query($sql, $con);
  153. // Mysql_num_row is counting table row
  154. $count=mysql_num_rows($retain);
  155. if($count < 1)
  156. {
  157. echo "Wrong user name";
  158. }
  159. }
  160. ?>
Add Comment
Please, Sign In to add comment