昨晚它工作正常现在我得到undefined errors
来自db的所有变量。如果我在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;
}
答案 0 :(得分:0)
您遇到哪些变量错误?好像你的问题可能是因为你没有用SQL返回任何结果 - 因此没有设置变量。
因此 - 将SQL循环之前的变量设置为空白或其他内容:
$dbname = null;
$dbpass = null;
$dbemail = null;
- 编辑 - 或者只是将if
语句放在while
循环中(如果您只期望最多一个结果......)