0

I'm relatively new to PHP and I'm creating a login form. The connection with my db and the password verification is working fine, but I can't find a solution for getting a "wrong password" feedback directly in my form like shown in the picture at the end.

My form requires just a password the user will get from me. The form code looks like that:

<form name="download" id="download" method="post" action="download.php">
         <label for="password">Passwort</label><br>
         <input type="password" id="password" name="password" required> <br>
         <input type="submit" id="submit" value="Download">
</form>

and my download.php like this:

$pw = ($_POST['password']);
$statement = $db->prepare("SELECT passwort FROM downloads WHERE id= :id");
$result = $statement->execute(array(':id' => 4));
$stored = $statement->fetch();
if(password_verify($pw, $stored['passwort'])){
    header("Location: test.pdf");
}
else{
    echo "Wrong password";
}

Instead of the else{ echo "wrong password";}, which is written on a blank new page, I would like to get some feedback like in the picture below.

Stackoverflow Login Form

Q.uestion
  • 183
  • 1
  • 11

0 Answers0