Why does my login returns undefined password index?
<p>Thanks for your time in advance.</p>

<p>I'm building an app with a login on it. On my proof of concept I used some old php, but then I realized I was vulnerable to SQL injection, so I switched to PDO.</p>

<p>I'm totally to PDO, so I don't fully understand how my code works ;). I'm getting an error telling me I have an "undefined password index on line 24". Can you show me what's wrong and what should I do?</p>

<p>Here's my code: </p>

<pre><code>if ( isset ( $_POST ['loginButton'] ) ) {

    $errMsg = '';

    //username and password sent from Form
    $username = trim ( $_POST ['username'] ) ;
    $password = sha1 (  trim ( $_POST ['password'] ) ) ;

    if ( empty ( $username ) ) {
        $errMsg .= 'You must enter your Username&lt;br&gt;';
    }

    elseif ( empty ( $password ) ) {
        $errMsg .= 'You must enter your Password&lt;br&gt;';
    }


    elseif ( $errMsg == '' ) {

        $records = $databaseConnection-&gt;prepare ( 'SELECT * FROM  users WHERE email = :username' ) ;
        $records-&gt;bindParam ( ':username', $username ) ;
        $records-&gt;execute () ;

        $results = $records-&gt;fetch ( PDO::FETCH_ASSOC ) ;

        if ( count ( $results ) &gt; 0 &amp;&amp; password_verify ( $password, $results ['password'] ) ) {

            header ( 'location:dashboard.php' ) ;
            exit;

        }

        else {
                $errMsg .= 'Username and Password are not found&lt;br&gt;';
        }

    }

}
</code></pre>