• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

ASP SQL avoiding multiple insert

Dear All,
I recieve emails from my users, I take the data and insert it to my database for future purposes.
However somethimes they oversend it to me. I mean they send the same mail and the date over and over again.
I want to let them know that I have already recieve the data and I want to insert it only once to my database.
But I want them to write me when ever they want apart from same thing.
I take the date with  t=now
Can use "now" and ip to avoid it?
I can let the user in 3 minutes to insert the same data?
How can I do that?

I'm aware of SQL injection, I  didn't send all the code to you.
What should I do?
thank you in advance.
name=request("name")
mesaj=request("mesaj")
phone=request("phone")
topic=request("topic")
email=request("email")
address=request("address")
markets=request("markets")
r= Request.ServerVariables("remote_addr")
t=now
 
 
set con = server.CreateObject("adodb.connection")
 
con.open("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
 
set rs = server.CreateObject("adodb.recordset")
			
 
sqlcumle = "insert into tablename(name,phone,Eposta,Markets,topic,Address,date,ip)  values('" & ad & "','" & tel & "','" & email & "','" & markets & "','" & konu & "','" & address & "','" & t & "','" & r & "')"
rs.open sqlcumle, con, 1, 3

Open in new window

0
BR
Asked:
BR
1 Solution
 
Daniel WilsonCommented:
sqlcumle = "If Not Exists (Select * from TableName Where name = '" & ad & "' and phone = '" & tel & "' and DateAdd(m,3, [Date]) > '" & t & "') insert into tablename(name,phone,Eposta,Markets,topic,Address,date,ip)  values('" & ad & "','" & tel & "','" & email & "','" & markets & "','" & konu & "','" & address & "','" & t & "','" & r & "')"

0
 
SvenTech Lead Web-DevelopmentCommented:
what is the primary key for the the table? or which bundle of values have to be unique?

you could do this asp script like:
<%
rs.open "SELECT COUNT(*) AS RowCount FROM table WHERE [check unique values here!]", con, 1, 3
 
If rs("RowCount") = 0 Then
 
  con.execute "INSERT INTO table (cols) VALUES (val)"
 
Else
 
  Response.Write "dataset allready exists!"
 
End If
%>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now