可能重复:
在数据库中找不到正确的电子邮件地址
我的 if else 语句有问题。当我在文本框中输入正确的用户名和电子邮件时,它会继续执行 else 语句并回显“您输入了错误的电子邮件地址”,而不是执行 if 语句并回显“您的详细信息正确”。即使我从数据库中输入了正确的用户名和与该用户相关联的正确电子邮件,有谁知道为什么它会回显错误的语句?
if (isset($_POST['resetbtn'])) {
//get form data
$user = $_POST['user'];
$email = $_POST['email'];
//make sure info is provided
if ($user) {
if ($email) {
if ((strlen($email) >= 7) && (strstr($email, "@")) && (strstr($email, "."))) {
$query = "SELECT TeacherUsername, TeacherEmail FROM Teacher WHERE TeacherUsername = ?";
// prepare query
$stmt = $mysqli->prepare($query);
// You only need to call bind_param once
$stmt->bind_param("s", $user);
// execute query
$stmt->execute();
// get result and assign variables (prefix with db)
$stmt->bind_result($dbTeacherUsername, $dbTeacherEmail);
//get number of rows
$stmt->store_result();
$numrows = $stmt->num_rows();
if ($numrows == 1) {
$row = $stmt->fetch();
$dbTeacherEmail = $row['TeacherEmail'];
//make sure email is correct
if ($email == $dbTeacherEmail) {
echo "Your details are correct";
} else {
echo "You entered in the Wrong Email Address";
}
} else {
echo "Please Enter in your Email";
}
} else {
echo "Please Enter in your Username";
}
}
}
}