MySQL select 替换文本等于值的列

MySQL select a column with replaced text where it equals a value

我最近注意到一个事实,即无论是否放置“.”,gmail 电子邮件地址都是相同的。在“@gmail.com”之前。所以 "myemail@gmail.com" 和 "my.email@gmail.com" 都发送到 "myemail@gmail.com".

因此,当用户在我的网站上注册时,我想检查他们是否没有使用此漏洞利用基本相同的电子邮件地址创建多个帐户。

我清理了他们发给我的电子邮件地址,使用 PDO 登录我的数据库,然后尝试 运行 此代码:

$data=$db->query("SELECT REPLACE(email,'.','') AS email_without_periods FROM account_data HAVING email_without_periods LIKE '".str_replace($sanitizedEmail,".","")."'");

if($row=$data->fetch()){
//It found a match between the sanitized email without decimals and the email rows without decimals. Hey, this dude's trying to create multiple accounts!
    $error="You're trying the email decimal trick! You sneaky devil... ";
}

但是,此输入不起作用:它似乎没有注册任何行。

当我用 LIKE '%".str_replace($sanitizedEmail,".","")."%'" 替换 LIKE '".str_replace($sanitizedEmail,".","")."'" 时,它带回了 所有 行。

我基本上想在数据库中搜索 str_replace($postEmail,".",""),但首先要删除 email 行中的所有句点。我正在使用 PDO。

我该怎么做?

您在 str_replace 中的参数顺序错误。应该是:

str_replace('.', '', $sanitizedEmail)

您使用的参数顺序与 SQL 的 REPLACE 函数相同,但它们不同。