We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

ASP SQL avoiding multiple insert

BR
BR asked
on
Medium Priority
266 Views
Last Modified: 2012-05-06
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

Comment
Watch Question

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 & "')"

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
SvenTech Lead Web-Development

Commented:
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

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.