Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $username = trim($_POST['username']);
  4. $password = trim($_POST['password']);
  5. /* Create a new mysqli object with database connection parameters */
  6. $mysqli = mysqli_connect('localhost', 'root', '', 'draftdb');
  7.  
  8. if(mysqli_connect_errno())
  9. {
  10. echo "Connection Failed: " . mysqli_connect_errno();
  11. exit();
  12. }
  13. /* Create a prepared statement */
  14. if($stmt = $mysqli -> prepare("SELECT Login_ID, Login_PW,
  15. FROM login
  16. WHERE Login_ID=? AND Login_PW =?"))
  17. {
  18.  
  19. /* Bind parameters
  20. s - string, b - boolean, i - int, etc */
  21. $stmt -> bind_param("ss", $username, $password);
  22.  
  23. /* Execute it */
  24. $stmt -> execute();
  25.  
  26. /* Bind results */
  27. $stmt -> bind_result($username, $password);
  28.  
  29. /* Fetch the value */
  30.  
  31. if($stmt->fetch() == true)
  32.  
  33. {
  34. $row =$query -> fetch();
  35. $_SESSION['name'] = $row;
  36. header("Location:/in.php");
  37. exit();
  38. }
  39. else
  40. {
  41. echo 'Invalid Login';
  42. }
  43.  
  44. /* Close statement */
  45. $stmt -> close();
  46. }
  47.  
  48. /* Close connection */
  49. $mysqli -> close();
  50. ?>
  51.  
  52. $a = array();
  53. while ($stmt->fetch()) {
  54. $a = array('username' => $username, 'password' => $password);
  55. }
  56.  
  57. $_POST['username'];
  58. $_POST['password'];
  59. $username;
  60. $password;
  61.  
  62. if($stmt->fetch() == true) { } // equals: if ($stmt->fetch()) { }
  63.  
  64. $sql = "SELECT Login_ID, Login_PW,
  65. FROM login
  66. WHERE Login_ID=?
  67. ";
  68.  
  69. $stmt = $mysqli->prepare( $sql );
  70.  
  71. // Do your thing...
  72.  
  73. // Make sure the user is found.
  74. if ( ! $stmt->rowCount() )
  75. return false;
  76.  
  77. // Retrieve your results as an associative array.
  78. $user = $stmt->fetch();
  79.  
  80. // Check the password.
  81. if ( ! $_POST['password'] == $user['Login_PW'] ) )
  82. return false;
  83.  
  84. $_SESSION['name'] = $user['Login_ID'];
  85.  
  86. header("Location:/in.php");
  87.  
  88. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement