prevent duplicate submissions to a database from an ASP form

S

Sandra G

I need help ASAP. I have a form where users can fill out the fields
firstname, lastname, and emailaddress. When the user submits the form,
I need ASP to call out to a SQL Server database to see if the
firstname, lastname and emailaddress the user submitted already exists
in the database. If they all do exist, the user should not be allowed
to submit the data but should be redirected to a page saying "sorry,
you have already entered that information" or something to that effect.

Thanks!
 
R

Ray Costanzo [MVP]

First name, last name, ~and~ e-mail? Typically an e-mail address by itself
is all you'd want to use. By checking all three, that would mean I could
register on your site as many times as I like with the same e-mail address.
All I'd have to do is change my name each time. But, I'm not your father.

Dim oADO, oRS, sSQL
Dim sFirstname, sLastname, sEmail

sFirstname = Request.Form("firstname")
sLastname = Request.Form("lastname")
sEmail = Request.Form("email")
sSQL = "SELECT email FROM yourtable WHERE Lastname=" & dbIn(sLastname) & "
AND Firstname=" & dbIn(sFirstname) & " AND Email=" & dbIn(sEmail)

Set oADO = CreateObject("ADODB.Connection")
oADO.Open yourConnectionstring
Set oRS = oADO.Execute(sSQL)
If oRS.EOF Then
''fine, not an exact match, insert the data next
Else
Response.Write "You exist."
End If
oRS.Close : Set oRS = Nothing
oADO.Close : Set oADO = Nothing


Function dbIn(s)
dbIn = "'" & Replace(s, "'", "''") & "'"
End Function


Ray at home
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top