> I wish to check firstname, lastname, emailaddress 
> for duplicates.

Many people here have pointed out that you can query the database before
allowing a duplicate insert to continue. For your purposes, you might have
something like this:

<cfquery name="qCheckForDuplicates" ...>
SELECT COUNT(*) AS ExistingRecords
FROM     table
WHERE  email = '#Form.Email#'
AND      firstname = '#Form.firstname#'
AND      lastname = '#Form.lastname#'
</cfquery>

<cfif qCheckForDuplicates.ExistingRecords>
 ... don't allow the insert, do something else instead ...
<cfelse>
 ... insert the record ...
</cfif>

To this, I can only add that you'll want to read all about the CFQUERYPARAM
tag, which you should use whenever you take values from the browser and use
them in an SQL statement as above.

However, what no one seems to have pointed out is that, if you don't want to
allow duplicate records, you should design your database to prevent this
possibility. In the above case, you'd want to create a unique index on the
three fields. You might do this by making the three fields a primary key;
this would be a "natural" primary key, as opposed to a "surrogate" primary
key that you'd get when you use an autonumber field or identity column.
Personally, I prefer surrogate keys, but I'd still recommend that you create
a unique index over what would correspond to your natural key - the three
fields in this case. To do this, look up the syntax for CREATE INDEX for
your particular database.

Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Your ad could be here. Monies from ads go to support these lists and provide more 
resources for the community. http://www.fusionauthority.com/ads.cfm

Reply via email to