比较PHP/MySQL中的两个电子邮件地址总是返回false [英] Comparing two email addresses in PHP/MySQL always returns false
问题描述
我正在尝试通过一个唯一的邀请代码链接注册用户,该链接已根据其电子邮件地址进行了检查.注册时,我正在检查他们发布的电子邮件地址是否与我们存储在数据库中的电子邮件地址匹配.一切似乎都运行良好,我已经验证了发送到检查功能的电子邮件和代码,但是由于某种原因,该消息不断返回false.我在这里想念什么?
I'm trying to register users from a unique invite code link which is checked against their email address. At registration I'm running a check to see if the email address they posted matches the email we have stored in the database. Everything seems to be running great, I have validated the email and codes being sent to the check function, but for some reason this continually returns false. What am I missing here?
public function CheckEmail($email, $code, $db)
{
$query = $this->db->prepare("SELECT 'email' FROM `userlogin` WHERE `code`= ?");
$query->bindValue(1, $code, PDO::PARAM_STR);
try
{
$query->execute();
$data = $query->fetch();
$confirmEmail = $data['email'];
if($confirmEmail == $email)
{
return true;
}
else
{
return false;
}
}
catch (PDOException $e)
{
die($e->getMessage());
}
}
推荐答案
您可能想要
"SELECT `email` FROM `userlogin` WHERE `code`= ?"
您将电子邮件用单引号引起来,而不是将其括起来,因此您实际上是在选择文本email
进行比较
You wrapped email in single quote marks and not back ticks, hence you were really selecting the text email
to compare against
这篇关于比较PHP/MySQL中的两个电子邮件地址总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!