Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • 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
Braveheartli
Asked:
Braveheartli
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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