当用户创建帐户时,我已成功设法在我的数据库中存储哈希密码,但是,当他们转到登录时,使用正确的密码返回我实施的“错误密码”错误消息。
$username = ($_REQUEST['username']);
$password = ($_REQUEST['password']);
if(isset($username) && isset($password)){
$sql = "SELECT password FROM users WHERE username = '$username';";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
$storedpw = $row['password'];
//checking the stored pw against the enetered one
if(password_verify($password, $storedpw)) {
mysqli_close($con);
$_SESSION["userVal"] = $username;
$_SESSION["user_image"] = $image;
header("location: adminPage.php");
} else {
$errmsg = "Invalid Username or Password.";
}
}
当我运行这个时,我收到了来自php的错误消息
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client :: 1:54231] PHP注意:未定义索引:D:\ UniServerZ \ www \ GRADEDUNIT1中的用户名第19行的login2.php
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client :: 1:54231] PHP注意:未定义的索引:D:\ UniServerZ \ www \ GRADEDUNIT1中的密码第20行的login2.php
[Mon May 30 14:14:10.631018 2016] [:error] [pid 7928:tid 1492] [client :: 1:54231] PHP注意:未定义的变量:D:\ UniServerZ \ www \ GRADEDUNIT1中的errmsg \第106行的login2.php
然而,当我回应出它们被定义的变量时。从登录表单
<form action="" method="post">
<input type="text" name="username" placeholder="Username" class="input" />
<input type="password" name="password" placeholder="Password" class="input" />
<br/><br/>
<!--<div class="g-recaptcha captcha" data-sitekey="6LcLdyATAAAAAE3WODrfikLzWadSCUKzhfuxFEXf"></div>
<br/>-->
<input type="submit" class="button button-primary" value="Log In" id="login"/>
</form>
所以我的最终问题是为什么当它应该匹配时它会返回错误? 我已经写出了MySQL语句并检查了它,看起来很好!我卡住了