我有一个数据库,其中有“ timeStamp”和“ email”不同的列。用户注册每天在此表中大约有9k-10k条目。
我不知道为什么,但是有时用户会在完全相同的timeStamp(甚至两秒匹配)上注册了相同的数据。 9k中每天大约有6-7个重复项。我应该在哪里寻找代码中的错误?
当我运行此查询时:
SELECT email, timeStamp, COUNT(*) FROM Users GROUP BY email, timeStamp HAVING COUNT(*) > 1
我每天得到7-8行。 (注册日期也插入表中)
$query = "INSERT INTO Users SET fname=:fname, email=:email, phone=:tel, lname=:lname, oras=:oras, IP=:ip, ansday=:dateAns, correct=:correct, agree18=:agree18, agree=:agree";
$crej = $conn->prepare($query);
$fname = htmlspecialchars(strip_tags($fname));
$lname = htmlspecialchars(strip_tags($lname));
$email = htmlspecialchars(strip_tags($email));
$tel = htmlspecialchars(strip_tags($tel));
$oras = htmlspecialchars(strip_tags($oras));
$crej->bindParam(":correct", $correctAns);
$crej->bindParam(":lname", $lname);
$crej->bindParam(":fname", $fname);
$crej->bindParam(":email", $email);
$crej->bindParam(":tel", $tel);
$crej->bindParam(":oras", $oras);
$crej->bindParam(":ip",$ip);
$crej->bindParam(":dateAns",$date);
$crej->bindParam(":agree18",$agree18);
$crej->bindParam(":agree",$agree);
$crej->execute();
为防止在同一天使用重复的电子邮件/电话号码,请执行以下操作:
$checker = "SELECT (if(u.email = :email, 1, 0) + if(u.phone = :tel, 1, 0)) AS counter , u.* FROM Users u WHERE (u.email = :email OR u.phone = :tel) AND (u.ansday = :dateAns)";
$checkUnique = $conn->prepare($checker);
$checkUnique->bindParam(":email", $email);
$checkUnique->bindParam(":tel", $tel);
$checkUnique->bindParam(":dateAns", $date);
$checkUnique->execute();