DB Save Remove Duplicates

georges999 27 Feb, 2014
I am wondering if when a user submits our form and it saves to a database, whether it can automatically removed if its a duplicate.

Example:

Record 23: Test Name - testemail@testemail.com - 01234567890
x
x
x
x
x
x
x
x
x
x
Record 34: Test Name - testemail@testemail.com - 01234567890

The database or a script will then run through our table, see if "Test Name" is there and then delete the just posted record.
GreyHead 27 Feb, 2014
Hi georges999,

You could do this with the Custom Serverside Validation action. Add a MySQL query to check the table and if the email is found end the form processing.

Bob
georges999 28 Feb, 2014
Thank you for your reply, I have looked at this and not too clued on the whole php thing? would it be something along the lined of

$db->query"INSERT INTO table_name (table,columns,go,here) values (column1, column2, column3, column4) WHERE NOT EXISTS (SELECT * FROM table_name WHERE column2 = $form->['email_input'])"


column2 = email input column in this example

Should that work?
GreyHead 01 Mar, 2014
Hi georges999,

I'd be very surprised if that worked, it looks as though you have cut and pasted odd bits of code together. Have you tested it?

This might be closer to what you need:
<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
      FROM `#__table_name`
      WHERE `column2` = '{$form->['email_input']}' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 0 ) {
  return false;
}
?>

Bob
georges999 03 Mar, 2014
To be honest, W3 schools and looking at a bit of other coding to try and piece something together.
Im not too bad when it comes to HTML and CSS but PHP is something that ive onley just dived into, so im still learning, Ill try yours and see what I get. Thank You
georges999 03 Mar, 2014
Just another thing, the table is called "rgh_chronoforms_data_PrizeDraw" so would the
"FROM `#__table_name`"
be "FROM `#__chronoforms_data_PrizeDraw`" or "FROM `#__rgh_chronoforms_data_PrizeDraw`"

Not sure I have my events setup correctly either.. Do I put the DB save under the OnSuccess of the Custom Server Side Validation?

DB Save Remove Duplicates image 1
georges999 06 Mar, 2014
Cant yet get this working, is the above image correct? Also im unsure of whether I use the table prefix or not?
georges999 17 Mar, 2014
I cant get this working correctly😟 can you help me. I have the follwing code in the Custom Server Side Validation
    <?php
    $db =& JFactory::getDBO();
    $query = "
        SELECT COUNT(*)
          FROM `#__chronoforms_data_PrizeDraw`
          WHERE `email_input` = '{$form->['email_input']}' ;
    ";
    $db->setQuery($query);
    $count = $db->loadResult();
    if ( $count > 0 ) {
      return false;
    }
    ?>


I have added the DB save on success and stuff as follows. But still cant get it to work.

DB Save Remove Duplicates image 2

[[>> I updated the code from a later post : Greyhead <<]]
georges999 15 Apr, 2014
I am still having trouble with this. I think you edited my post greyhound but the code is still the same as what I have in Joomla.

Is my above image theoretically correct?
Max_admin 16 Apr, 2014
The code and setup is correct, you still get duplicate saves ?

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
georges999 16 Apr, 2014
No its not saving and its redirecting to the on Fail URL. I have checked the Database table and the record im using to test is not in there.
Max_admin 16 Apr, 2014
What's the name of the field holding the email address in the form and in the database table ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
georges999 17 Apr, 2014
This is my DIV for the email field:
<div class="ccms_form_element cfdiv_text" id="email_input1_container_div" style=""><label>Email</label><input maxlength="150" size="50%" class=" validate['required','email']" title="" type="text" value="" name="email_input" />
<div class="small-message">Please insert your email here.</div><div class="clear"></div><div id="error-message-email_input"></div></div>

These are my headers for the database table:
 cf_id 	cf_uid 	cf_created 	cf_modified 	cf_created_by 	cf_modified_by 	cf_ipaddress 	cf_user_id 	name_input 	email_input 	mobile_input 
GreyHead 17 Apr, 2014
Answer
Hi georges999,

Looking at this again this line
       WHERE `email_input` = '{$form->['email_input']}' ;
should probably be
       WHERE `email_input` = '{$form->data['email_input']}' ;


Bob
georges999 17 Apr, 2014
Thank you so much works a treat now!! You have been very helpful!
This topic is locked and no more replies can be posted.