2017-05-27 2 views
-3

Wo liege ich falsch? Dieser Fehler tritt nur auf, wenn ich data-toggle = "password" verwende - siehe Code unten.Hinweis: Undefinierter Index: Passwort in E: x htdocs crud slp slp login.php in Zeile 10

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> 
+0

Bitte geben Sie Ihren Code hier ein. – Filburt

+0

zu lange von 2786 Zeichen –

+0

Geben Sie den entsprechenden Code hier - wenn der Fehler in Zeile 10 ist, sollte es möglich sein, eine [MCVE] zu buchen. – Filburt

Antwort

0

Ich löste es durch if (isset ($_GET ["password"])) {} nach Zeilennummer 6. Fehler beim Hinzufügen gegangen ist. Ist es ein guter Ansatz, so etwas zu beheben?

Verwandte Themen