Guest User

Untitled

a guest
Feb 27th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. <?php
  2. // mysql_connect is deprecated and not secure
  3. // You can pass the DB name as the fourth argument of mysqli_connect
  4. $conn = mysqli_connect('localhost','accounting','', 'ffdbR4fsa');
  5.  
  6. if (! isset($_SESSION)) {
  7. session_start();
  8. }
  9. ?>
  10.  
  11. <form action="" method="post">
  12. <table width="50%" border="0">
  13. <tr>
  14. <td><h3>Admin Log In</h3></td>
  15. </tr>
  16. <tr>
  17. <td><label>Username</label><input type="text" name="username" placeholder="Username"></td>
  18. </tr>
  19. <tr>
  20. // Password type was missing
  21. <td><label>Password</label><input type="password" name="password" placeholder="Password"></td>
  22. </tr>
  23. </table>
  24. <input type="submit" value="Log In" name="s">
  25. </form>
  26. <?php
  27.  
  28. if (isset($_POST['s'])) {
  29. // the post field must match the input field name, changed to username to match
  30. $user = $_POST['username'];
  31. $pass = $_POST['password'];
  32.  
  33. // again mysq_query is deprecated
  34. $result = mysqli_query($conn, "select * from admin_list where user_name ='$user' and password = '$pass'");
  35.  
  36. // agai mysq_num_rows is deprecated
  37. if (mysqli_num_rows($result) === 1) {
  38. $_SESSION['is_admin'] = True;
  39. $_SESSION['user'] = $user;
  40. echo "Logged in as $user";
  41. } else {
  42. $_SESSION['is_admin'] = False;
  43. $_SESSION['user'] = NULL;
  44. echo 'Invalid login or password';
  45. }
  46. }
  47.  
  48. // Remove the closing tags, just a good practice so another file can continue
  49. // Some ; were missing too
Add Comment
Please, Sign In to add comment