MySQL Error when checking for duplicate emails

4 posts by 2 authors in: Forums > CMS Builder
Last Post: July 22, 2013   (RSS)

By gregThomas - July 19, 2013

Hi Jerry,

The error suggests that the table name your using doesn't exist, I would double check that the table your using is correct. 

Also, it looks as if the IN statement you're using is the wrong way around, I would recommend using = to check for the e-mail address instead.

Here is some updated code:

$email = mysql_escape(@$_REQUEST['email_address']);
$count = mysql_count('publicity_listings', "email_address = '$email'");

if ($count > 0 ) { $errorsAndAlerts .= "That Email Address already exists.\n"; }

So first I've escaped the e-mail address, then I've used the mysql_count function to check if the e-mail address does appear in the table. The mysql_count function takes two variables, the first is the table name, and the second is a where statement.

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By gkornbluth - July 19, 2013

Hi Greg,

How many ways can I say I’m sorry?

I really did play with this for at least a few hours before I finally posted.

The reality is that both versions of the code seem to work now that I (finally) noticed that I had left out the “i” in publicity in the original table name.

Eyes can really play tricks on you.

Sorry for the bother I caused.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By gregThomas - July 22, 2013

Hi Jerry,

Not a problem! Glad you've got it working.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com