-1

When a user fill in their email address in an form, I will check if the email address exist in the database.

Why are not the code working?

Here is my code:

php

<?php

session_start();

require 'database.php';

if(!empty($_POST['email'])):

  $records = $conn->prepare('SELECT id,email,password FROM users WHERE email = :email');
  $records->bindParam(':email', $_POST['email']);
  $records->execute();
  $results = $records->fetch(PDO::FETCH_ASSOC);

  echo 'Working';

    if(isset($_REQUEST['email'])){

    $email_to = $_REQUEST['email'];
    $email_subject = "Forgotten password";
    $email_from = "password@scoreplay.net";


    $email_message = $results['password'];

    $headers = 'From: ' .$email_from . "\r\n";
    @mail($email_to, $email_subject, $email_message, $headers);

    #header("Location: /success.php");

  exit();

}

endif;

?>
Amandus
  • 9
  • 3

1 Answers1

1

You have to echo the result to see after if/else condition like this

session_start();

require 'database.php';

if(!empty($_POST['email']) ):

  $records = $conn->prepare('SELECT id,email,password FROM users WHERE email = :email');
  $records->bindParam(':email', $email);
  $records->execute();
  $results = $records->fetch(PDO::FETCH_ASSOC);

  $message = '';

  if(count($results) > 0 && password_verify($_POST['password'], $results['password']) ){

    $message = 'Success!';

  } else {
    $message = 'Sorry, those credentials do not match';
  }
  // Now, you just have to add 
 echo $message;  
endif;
tikimti-mvrht
  • 242
  • 2
  • 12