It cannot find the correct email address in the da

2019-03-07 06:46发布

问题:

I want to check for a valid email address and then see if the email address is in the database. At the moment the validation for a valid email address works fine. But if I enter in an email address which is in the database such as "nickfrosty@yahoo.com", instead of echoing the message You have entered in the Correct Email Address, it echos the complete opposite message and echos You entered in the Wrong Email Address. So this is making me think that it cannot find the email address in the database even though I am sure the email address is in the database.

So my question is that why can't it find the email address in the database and hence echos the message that I have entered in the wrong email address?

Below is the code (mysqli/php):

if ( (strlen($email) >= 7) && (strstr($email, "@")) && (strstr($email, ".")) ){

echo "You have entered in the Correct Email Address";

}
else{
echo "You entered in the Wrong Email Address";
}

回答1:

$query = "SELECT TeacherUsername, TeacherEmail FROM Teacher WHERE TeacherUsername = ?";

means you check the input against TeacherUsername, not TeacherEmail. You might want to try

$query = "SELECT TeacherUsername, TeacherEmail FROM Teacher WHERE TeacherEmail = ?";