0

我尝试使用此代码检查我的数据库中是否存在电子邮件地址 3 次

$checkEmail = $_POST['email'];

$query = "SELECT email, count(*) $checkEmail FROM participanti GROUP BY email HAVING $checkEmail = 3";
$result = mysql_query($query) or die(mysql_error());
if ($row = mysql_num_rows($result)){

    if ($row[$checkEmail] == 3) {
        echo "NY";
    }
    else{

但在我的网站上它说

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@mail.com FROM participanti GROUP BY email HAVING address@mail.com = 3' at line 1
4

2 回答 2

1
$query = "SELECT email, count(*) as total 
FROM participanti 
WHERE email = '$checkEmail' 
GROUP BY email 
HAVING total = 3";
于 2013-09-02T17:40:47.920 回答
0

问题是您给列一个无效的名称。

CntOfEmails你应该使用类似的东西

所以像

$query = "SELECT email, count(*) CntOfEmails FROM participanti GROUP BY email HAVING CntOfEmails = 3";
于 2013-09-02T17:40:49.163 回答