I am an absolute beginner and php and am in the middle of making my first login page with php and mysql. at the moment I am not worried about mysql injection as I am still learning but i will put my real escape string later on when I finalize.
I am wondering why, no matter what I put, the password keeps returning as an incorrect password. At this point I am trying to test if I can get the correct password before i start writing for sessions.
When I create a password into the database I used md5 to encrypt the passwords, I'm not sure if this makes a difference. But I feel like it could affect the verify password function. Please take a look at the code below.
I started web development about 3 weeks ago so please excuse my basic trivial messy code writing! I will probably put a lot of it into a functions php so I can refer back to functions after I get the functionality right!
I am particularly interested in why the password_verify doesnt work! it keeps returning as incorrect is it because of the messy if within ifs or a type or missuse. Please let me know your opinions :)
<?php
include 'dbconnect.php';
$emailerror = $passworderror;
if(isset($_POST['submit']))
{
    
    $email= $_POST["email"];
    $password= $_POST["password"];
  
    if (empty($email)) {
    $emailerror = "*Email must be entered";
    }
    elseif (!filter_var($email, FILTER_VALIDATE_EMAIL))
    {   
    $emailerror= "*Invalid email address Entered";    
    }
    
 // check if email exists
    else{         
        $emailquery = ("SELECT * FROM `Potential_Employee` WHERE `Email` = '$email'");
        $emailcheckresult = mysqli_query($connection, $emailquery);
        
         
            if(mysqli_num_rows($emailcheckresult) == 1){            
            $row=mysqli_fetch_assoc($emailcheckresult);
            
                 if (password_verify($password, $row['Password'])){
                     $passworderror = "*Password is correct";
                 }
                 else{
                      $passworderror = "Password is Incorrect";
                 }
                 }
            else{
                 $emailerror = "*Email does not exist";
        }
        
      }
                 
    if (empty($password)) {
    $passworderror = "*Password must be entered";
    }
    
    elseif (strlen($password) < 4 )
    {
        $passworderror= "*Password Has to be greater than 8 Characters";
    }
    
    ?>