Forums

Checking Database for duplicated entry

yhjohn 13 Feb, 2015
Hi Guys,

Been a long time fan of chronoform,
recently i've started developing solely on wordpress and i'm having a bit of an issue here basically can't find any documentation on it.

I am doing a newsletter subscription form and basically the form only saves to database using DBsave

So when a user submit a form, it should technically go to the database, and find the email column and if email exist, it will prompt message saying already registered

So naturally I use event switcher for this task.

This is what I have so far.

<?php
$db_host = 'xx';
$db_user = 'xx';
$db_pass = 'xx';
$db_name = 'xx';

/* Connect to the new database */
$externalQuery = new wpdb($db_user, $db_pass, $db_name, $db_host);

$match = $form->validation_errors['email'];

$newQuery = $externalQuery->get_results("SELECT COUNT(*) FROM cswp_chronoengine_chronoforms_datatable_eNewsletter WHERE  email = '$match'") or die(mysql_error());

if ($newQuery) {
   return "fail";  // user already registered
} else {
   return "success";
}
//print_r($newQuery);

?>


except that it woun't really work. I'm figuring this part out

$form->validation_errors['email'];


Is that correct?

This one i took from joomla but i'm not sure if it is correct in WP
Max_admin 14 Feb, 2015
Hi yhjohn,

What should this line actually do:
$match = $form->validation_errors['email'];

? get the logged in user's email or the email field value ??

I have no idea how to get the logged in user's email in WP, but if its meant to return a field value then please try:
$match = $form->data['email'];


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.