I have built an application on the site which captures a couple of fields including 'email' and posts it to some DB which i have having a table named 'data.' I am while using jQuery Validate wordpress plugin to make certain all fields are complete, though I can not have duplicate emails within the db.

The wordpress plugin included a script named emails.php so it calls when verifying the area data and here's the code:

$request = trim(strtolower($_REQUEST['email']));
$emails = array('steam@valve.com', 'bill@gates.com', 'blocked@email.com');
$valid = 'true';
foreach($emails as $email) {
if( strtolower($email) == $request )
    $valid = '"Thats already taken."';
echo $valid;

This snippet is just checking your email which are listed. It is possible to method to query the DB to look with the table 'data' and appearance the 'emails' to ascertain if there is a duplicate and hopefully publish a mistake message if it's?

Also, the script does appear to operate after i use the example emails so it's basically 'working' I simply need to tweak it to determine the DB.

Put a originality constraint around the email column.

Don't use a problematic "Choose before Place" approach. There'll always be a race condition involving the "Choose" along with a subsequent "Place" unless of course you are inside a global transaction, that we doubt may be the situation here.

You need to put a distinctive constraint around the email column after which simply make an effort to Place the brand new record and catch the originality SQL error. You are able to catch the mistake by checking the mistake code, for MySQL for instance it's 1062 or 23000 with respect to the driver.

First, put a UNIQUE constraint around the email column. Then, at register, run the next query:

SELECT COUNT(*) as 'count' FROM `data` WHERE email = 'requested@email.com';

You'd simply need to write a question to see if the e-mail is incorporated in the table:

$query = SELECT count(*) AS `total` FROM `data` WHERE `email` = '{$request}'
$row = mysql_fetch_assoc(mysql_query($query));
if($row['total']) echo false; //exists
else echo true; //doesn't exist

edit designed to 'echo' and never 'return'

You could do this perhaps a php code that inspections the DB for existing values while using mysql_num_rows command.

Something similar to this:

$result = mysql_query("SELECT email from accounts where email = $email_to_check");
$found = mysql_num_rows($result);

if ($found > 0) { echo "Email already exists"; }
else .....