MySQL Error when checking for duplicate emails

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

By gkornbluth - July 18, 2013

Hi All,

I’m not using the membership plugin for this client.

When a "create a new record" form is submitted, I’m trying to check for duplicate email addresses in a table called publicity_listings using  mysql_select_count_from with this code:

  // check for duplicate email
   $count = mysql_select_count_from('publicity_listings', "'".mysql_escape($_REQUEST['email_address'])."' IN (email_address)");
 if ($count > 0 ) { $errorsAndAlerts .= "That Email Address already exists.\n";
 }

but when I submit the form I’m getting this error and I don’t know how to remedy the issue.

mysql_count() MySQL Error: Table 'jeannes_ds.cms_publicity_listings' doesn't exist (at old_alias_functions.php line 6 in function mysql_count)

I’d eventually like to redirect the visitor to an update page that shows the information from the duplicate record, but need to get this resolved first.

I've attached the entire viewer in case it's of some help.

Thanks,

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
Attachments:

publicity-add-13.php 17K

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