Reputation: 1
I try to check if an email address exists in my database for 3 time with this code
$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{
But on my website it says
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 [email protected] = 3' at line 1
Upvotes: 0
Views: 623
Reputation: 341
$query = "SELECT email, count(*) as total
FROM participanti
WHERE email = '$checkEmail'
GROUP BY email
HAVING total = 3";
Upvotes: 1
Reputation: 166396
The problem is that you are giving the column an Invalid name.
You should use something like CntOfEmails
or such
so something like
$query = "SELECT email, count(*) CntOfEmails FROM participanti GROUP BY email HAVING CntOfEmails = 3";
Upvotes: 0