Check if a Database Record Already Exists Before Inserting a New Entry

Check the data in your Database before inserting possible duplicate data

Using server-side data validation from server connect you can check if a record already exists in the database. This is useful when new users register to your site so you can check if the email is already used and if it is display an error message, while at the same time stopping the server insert action from inserting duplicate data.

Step 1: Select your Insert Action(1) and right click the step before the insert record step(2):

Step 2: Select Validator:

Step 3: Select Add Validate Data:

Step 4: From the validate date properties panel click validate options:

Step 5: Click the add new(+) button:

Step 6: Double click the expression field to display the dynamic data picker icon, then click the dynamic data picker:

Step 7: Select the POST variable (form input) who’s value you want to validate. In our case this is the email input field in our pages form, click select when done:

Step 8: Then add a new validation rule for the selected expression:

Step 9: Open the Database category:

Step 10: And select Does not exist in database:

Step 11: Select your database connection:

Step 12: Select the database table you want to insert your data into:

Step 13: And select the database table column you want to use for the existing record check:

Step 14: Customize the error message that will display if a record does already exist:

Step 15: In the linked field enter the “name” of the form field, which is on your page. If you don’t do this, the error message won’t appear on the page:

Step 16: Click Save:

Step 17: Then save your server action and you are done. The insert will not run if the record already exists in the database.