Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $serverName = "localhost"; // Variables to access the user database
- $username = "root";
- $password = "";
- $database = "snake_database";
- $errors = []; //Array of all the errors to display to the user
- $conn = mysqli_connect($serverName, $username, $password, $database); //Connect to the database
- if(!$conn){ //If the database failed to connect
- die("Database failed to connect: " .mysqli_connect_error()); //Display an error message
- }
- $sql = "SELECT * FROM users WHERE username = ?"; // Select only the rows having the given $_POST['username']
- $stmt = $conn->prepare($sql);
- $stmt->bind_param("s", $_POST['username']);
- $stmt->execute();
- $recordSet = $stmt->get_result()->fetch_array();
- echo "all the rows selected:\n";
- var_dump($recordSet);
- if(count($recordSet) === 0){
- echo "Error, the given username is not present in the database";
- }else{
- $record = $recordSet[0];
- echo "only the row we care about:\n";
- var_dump($record);
- if(password_verify($password, $record['password'])){
- echo "you entered the correct password";
- }else{
- echo "password was incorrect";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement