显示错误:未定义索引:密码

时间:2018-05-29 13:16:53

标签: php mysql pdo undefined

    <?php
session_start();

//DB configuration Constants
define('_HOST_NAME_', 'localhost');
define('_USER_NAME_', 'user');
define('_DB_PASSWORD', '');
define('_DATABASE_NAME_', 'user');

//PDO Database Connection
try {
    $databaseConnection = new PDO('mysql:host=localhost; dbname=user; ', 'root', '');
    $databaseConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

if(isset($_POST['login'])){
    $errMsg = '';
    //username and password sent from Form
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $hashpass = hash('sha512',$password);


    if($username == '')
        $errMsg .= 'You must enter your Username<br>';

    if($password == '')
        $errMsg .= 'You must enter your Password<br>';


    if($errMsg == ''){
        $records = $databaseConnection->prepare('SELECT user_id,user_name,user_password FROM  user WHERE user_name = :username');
        $records->bindParam(':username', $username);
        $records->execute();
        $results = $records->fetch(PDO::FETCH_ASSOC);                                           //line 91
        if(count($results) > 0 && password_verify($hashpass, $results['password'])){
            $_SESSION['username'] = $results['username'];
            header('location:index.php');
            exit;
        }else{
            $errMsg .= 'Username and Password are not found<br>';
        }
    }
}

你好,我在dbh中有用户名和密码哈希,我有这个错误:注意:未定义索引:密码在C:\ wamp64 \ www \ social-network \ register.php第91行调用堆栈#Time记忆功能位置

0 个答案:

没有答案