注意:未定义的索引:第10行的E:\ x \ htdocs \ crud \ slp \ slp \ login.php中的密码

时间:2017-05-27 07:27:57

标签: javascript

我哪里错了?这个错误只在我使用data-toggle =“password”时发生 - 请参阅下面的代码。

https://gist.githubusercontent.com/pomy/77047de0962f6a17d8459a8a51083952/raw/997f33425212eba407902dfa9e0e6ad52180e033/%2520data-toggle=%2522password%2522

    <?php
session_start();
require_once "config.inc.php";
$email = '';
$password='';
$errors = array();
//Checking the request method post to know if the form really posts any data
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $email = strip_tags($_POST['email']);
    $password = strip_tags($_POST['password']);

    //perfroming the validation 
    if(empty($email)){
        $errors[] = "Email field is required"; 
    }
    if(empty($password)){
        $errors[] = "Password field is required"; 
    }

    //You are goo to go
    if(empty($errors)) {
        $sth = $conn->prepare("SELECT * FROM users WHERE email = :email LIMIT 1");
        $sth->bindParam(':email', $email, PDO::PARAM_STR);
        $sth->execute();
        $user = $sth->fetch(PDO::FETCH_OBJ);
        if(!empty($user)) {
            //Verifying the password
            $hashedPwdDB = $user->password;
            if (password_verify($password, $hashedPwdDB)) {
                $_SESSION['user_id'] =  $user->user_id;
                $_SESSION['name'] =  $user->name;
                $_SESSION['email'] =  $user->email;
                header("Location:dashboard.php");
                exit;
            }   
            else {
                $errors[] = "Invalid login"; 
            }   

        }
        else {
            $errors[] = "Invalid login"; 
        }
    }

}



?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Tutsplanet Login Form</title>

<!-- Bootstrap -->
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous">
<!-- login with show password -->
    <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-show-password/1.0.3/bootstrap-show-password.min.js"></script>
</head>
<!-- login with show password // -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script></head>
<body>
<div class="container" style="width:20%;">
  <form class="form-signin" method="post">
    <?php if(!empty($errors)):?>
    <div class="alert alert-danger">
    <?php foreach($errors as $error):?>
    <?php echo $error,"<br>";?>
    <?php endforeach;?>
    <?php endif;?>
    </div>
    <h2 class="form-signin-heading">Please sign in</h2>
    <label for="inputEmail" class="sr-only">Email address</label>
    <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus name="email">
    <label for="inputPassword" class="sr-only">Password</label>
            <input type="password" id="password" name="password" class="form-control" data-toggle="password" autocomplete="off">

    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
  </form>
</div>
<!-- /container -->
<script type="text/javascript">
    $("#password").password('toggle');
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

我通过在第6行之后添加if (isset ($_GET ["password"])) {}来解决它。错误已经消失。这是一个很好的修复方法吗?