昨晚它工作正常,现在我得到undefined errors
了来自数据库的所有变量。如果我在循环之后回显变量,while
它们就在那里,但是一旦它们命中,if
我就会得到未定义的错误。
<?php
session_start();
include "connect.php";
include "report_errors.php";
$name = $_POST['name'];
$password = $_POST['password'];
$sql = $db->prepare("SELECT * FROM admin where username = :name AND
password = :password");
$sql->bindValue(':name', $name);
$sql->bindValue(':password', $password);
$sql->execute();
while($row = $sql->fetch())
{
$dbname = $row['username'];
$dbpass = $row['password'];
$dbemail = $row['email'];
}
if($name == $dbname && $password == $dbpass)
{
$_SESSION['loggedin'] = "yes";
$_SESSION['name'] = $name;
$_SESSION['pass'] = $password;
$_SESSION['email'] = $dbemail;
$url = "Location: yackimo_register_form.php";
header($url);
exit;
}
if($name == $dbname && $password != $dbpass)
{
$error = "invalidPassword";
$url = "Location: login.php?error=$error";
header($url);
exit;
}