ASP SQL avoiding multiple insert

Posted on 2009-02-17
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.







r= Request.ServerVariables("remote_addr")


set con = server.CreateObject("adodb.connection")"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 & "')" sqlcumle, con, 1, 3

Open in new window

Question by:Braveheartli
    LVL 32

    Accepted Solution

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

    LVL 11

    Expert Comment

    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:
    <% "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)"
      Response.Write "dataset allready exists!"
    End If

    Open in new window


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now