Advertisement
Guest User

Untitled

a guest
Feb 11th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. $serverName = "localhost"; // Variables to access the user database
  4. $username = "root";
  5. $password = "";
  6. $database = "snake_database";
  7. $errors = []; //Array of all the errors to display to the user
  8.  
  9. $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
  10.  
  11. if(!$conn){ //If the database failed to connect
  12. die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
  13. }
  14.  
  15. $sql = "SELECT * FROM users WHERE username = ?"; // Select only the rows having the given $_POST['username']
  16. $stmt = $conn->prepare($sql);
  17. $stmt->bind_param("s", $_POST['username']);
  18. $stmt->execute();
  19. $recordSet = $stmt->get_result()->fetch_array();
  20.  
  21. echo "all the rows selected:\n";
  22. var_dump($recordSet);
  23.  
  24. if(count($recordSet) === 0){
  25. echo "Error, the given username is not present in the database";
  26. }else{
  27. $record = $recordSet[0];
  28. echo "only the row we care about:\n";
  29. var_dump($record);
  30. if(password_verify($password, $record['password'])){
  31. echo "you entered the correct password";
  32. }else{
  33. echo "password was incorrect";
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement