User Database

How do I keep from getting duplicate entries in my collections? My users are entering information in a form and I don’t want the duplicate information, can I filter the entry by a single column linked to the item?

Hi,

I’m not sure that I fully understand what is the issue. Please share with us the code you’ve used, a screenshot of the issue and the site URL so that we can better understand what you were referring.

Thanks,
Tal.

Just add the fields that you don’t want duplicated as a primary key then the db integrity won’t allow duplicates of the primary key.

jmd, thanks for the suggestion but the field I want to not duplicate is set as the key. I have added some pics to help explain.


This is the Data/Collection table. I want to enter data and not duplicate the Unit#. I would like when the unit number is entered again the entry should be able to edit both the location and notes field without entering another (duplicate) unit number.


This is the data entry page. Notes are freely entered but location is determined by a drop down list. Unit number and notes are manual entries. All fields are required to submit.


Once entered, data is displayed according to the page requirements via a table. This page displays units at the Mechanics 23 location. You can see who duplicate entries can complicate the page data as the unit would show in multiple locations instead of the correct one. Any input or help would be greatly appreciated. Please keep in mind I have limited coding ability so if needed the directions would need to be simple. Thanks, Dan.

Remove LAST_UPDATED from the key. Because the combination of UNIT#+LAST_UPDATED makes each record unique. In this case, you want ONLY the UNIT# as part of the primary key.

I removed the LAST_UPDATED from the column in my data base but unfortunately the results are still the same. Would you have another suggestion?


I tried on both bases and removed it from my tables as well.

Hello Dan,

Preventing duplicates using purely datasets is not possible.

In order to accomplish that you will need to build a form using wix-data .
Instead of finding dups after the fact, you can prevent them from occurring in the first place by using data hooks .

All you need to do is implement a “before insert” hook (and maybe a “before update” hook), that looks for unit-ID with the same properties (can be done with query ), and either perform an update or an insert according to the results.

Thank you for the information. I however don’t know how to write that code. Could you provide an example for me that I could copy and paste or insert?

i also have the same problem… can someone suggest a code example to prevent a duplicate?

Hay lockerdan, Roy,

There are two modes for writing data (out of three modes) in a dataset.

Write only dataset - always creates a new item in the database. It is intended for forms, where each form submission is something different. My guess this is not what you intend.

Read / Write dataset - can read items, update existing items and do a lot more with the data. In fact, this is the list of actions a read / write dataset has -

Using those operations, you can create an application that can

  1. add new items - the new action creates a new empty item
  2. update an item - connect inputs to the dataset, edit data, submit saves the changes to the same item.
    2.5 the revert action resets any changes to an item back to the data stored in the database.
  3. delete an item - using the delete action
  4. browser between items - using the next / previous item actions

It sounds to me you are looking at using a read / write dataset. Have you tried using one?

Yoav,

  I have tried to just use read and write to complete this task however I have found that when in read and write mode the data on the first line of my collection is always over written and no new information is logged into the collection. If I change the mode to write only, it will enter data but will not update previous entry's and it allows duplication of the Primary field. Please help me resolve this as the entire web site functions around being able to enter data without duplication and being able to edit data. 

Thanks,
Dan

I have also made a discovery, My user input elements don’t clear back to the placeholder text after data entry. If the data would clear it then will add data to the collection. Is there a way to clear all input data with a button or a line of text?

Hi, can we get an explanation how can we avoid duplicates in our database based on a primary key? this is a very simple question and every database we know has this simple capability. many thanks for your help :slight_smile:

BTW - i also have the problem where my user input elements don’t clear back to the placeholder text after data entry … :frowning:
i think that this problem started after i added a drop down list element that get its list from another collection, but continues even after i deleted the the drop down list element.

Hi Roy, I found that in read and write mode on your data set causes your forms not to clear. On my it also only edits or changes the top line of data(first item) in a collection. If you change it to read only the placeholder text will return.

Hi Lockerdan :slight_smile:
Thanks! This fixed the problem.
BTW - i was able to prevent new duplicates by following the code instructions here :

you will need to make some adjustment to match your database but it works…

Hi There, I’m new in Wix and I like to create a database that don’t allow duplicate entry in my database. can someone show me how?

Many thanks
Raymond