dcsimg
www.webdeveloper.com
Results 1 to 5 of 5

Thread: Insert Statement Duplicating...

  1. #1
    Join Date
    Aug 2005
    Posts
    18

    Insert Statement Duplicating...

    Has anyone ever came across a situation where running an insert statement into a database was running twice everytime? There are no loops yet the page is inserting two records everytime the link is hit...

  2. #2
    Join Date
    Oct 2005
    Posts
    34
    This shouldn't happen. There must be an issue with the code that inserts the record...

  3. #3
    Join Date
    Aug 2005
    Posts
    18

    Code

    This appears to be correct to me:

    myLast = Request("txtLast")
    myFirst = Request("txtFirst")
    myCompany = Request("txtCompany")
    myAddress = Request("txtAddress")
    myCity = Request("txtCity")
    myState = Request("txtState")
    myZip = Request("txtZip")
    myPhone = Request("txtPhone")
    myEmail = Request("txtEmail")
    myClientID = Request("txtClientID")
    myTotal = 1

    myEventID = cint(Request.Querystring("EventID"))
    myType = cstr(Request.Querystring("Type"))
    myPassword = "password"

    if (myLast = "") OR (myFirst = "") Then
    response.write("<h1>Registration Failed</h1><br><BR><BR>")
    response.write("You must complete all *Required fields. Please use your back button and complete all fields before advancing.")
    response.write("<BR><BR><BR><BR><BR><BR><BR><BR><BR>")
    Else

    Set ls=Server.CreateObject("ADODB.recordset")
    ls.open "SELECT * FROM tblEvents WHERE EventID = '"&myEventID&"'", conn
    myDesc = ls("Event_Desc")
    myAvailable = ls("Event_Avail") - ls("Event_Taken")
    myClassSize = ls("Event_Avail")
    myUpdate = ls("Event_Taken") + 1

    ls.close

    Set ds=Server.CreateObject("ADODB.recordset")
    ds.open "SELECT Max(tblDetails.DetailsID) AS MaxofDetailsID FROM tblDetails", conn
    myDetailID = cint(ds("MaxofDetailsID"))
    myDetailID = myDetailID + 1

    if (myPassword = myVerify) And (myPassword <> "") Then
    if myTotal <= myAvailable Then
    response.write("<h1>Registration Successful!</h1><br>")
    response.write("<b>"&myDesc&"<br>")
    response.write(myDate&"<BR>")
    response.write(myLocation&"</b><br><BR><BR>")
    response.write("<table cellspacing='2'><tr><td>Name:</td><td>"&myLast&", ")
    response.write(myFirst&"</td></TR>")
    response.write("<tr><td>Client ID#:</td><td>"&myClientID&"</td></tr>")
    response.write("<tr><td>Company:</td><td>"&myCompany&"</td></tr>")
    response.write("<tr><td valign='top'>Address:</td><td>"&myAddress&"<BR>")
    response.write(myCity&", ")
    response.write(myState&", ")
    response.write(myZip&"</td></tr>")
    response.write("<tr><td>Phone:</td><td>"&myPhone&"</td></tr>")
    response.write("<tr><td>Email:</td><td>"&myEmail&"</td></tr>")
    response.write("<tr><td>Total Seats:</td><td>"&myTotal&"</td></tr></table>")

    Set ts=Server.CreateObject("ADODB.recordset")
    ts.open "SELECT Max(tblContacts.ContactID) AS CountOfContactID FROM tblContacts", conn
    myCount = cint(ts("CountofContactID"))
    myCount = myCount + 1


    Set rs=Server.CreateObject("ADODB.recordset")
    rs.open "INSERT INTO tblDetails (DetailsID, Details_ContactID, Details_EventID) Values ('"&myDetailID&"', '"&mycount&"', '"&myEventID&"')", conn

    rs.open "INSERT INTO tblContacts (ContactID, contact_Company, Contact_Last, Contact_First, Contact_Address, Contact_City, Contact_state, Contact_Zip, Contact_Email, Contact_Phone, Contact_Reserve, Contact_ClientID, Contact_Type) Values ('"&myCount&"', '"&myCompany&"', '"&myLast&"', '"&myFirst&"', '"&myAddress&"', '"&myCity&"', '"&myState&"', '"&myZip&"', '"&myEmail&"', '"&myPhone&"', '"&myTotal&"', '"&myClientID&"', 'External')", conn


    if (myUpdate = myClassSize) Then
    myLink = cstr("CLOSED")
    else
    myLink = cstr("OPEN")
    end if

    Set bs=Server.CreateObject("ADODB.recordset")
    bs.open "UPDATE tblEvents Set Event_Link= '"&myLink&"', Event_Taken= '"&myUpdate&"' WHERE EventID = '"&myEventID&"'", conn

    Else
    response.write("<h1>Registration Failed</h1><br><BR><BR>")
    response.write("There are not enough available seats to accomodate your party. Please call 800-381-0053 and ask for an available Account Executive to assist you.")
    response.write("<BR><BR><BR><BR><BR><BR><BR><BR><BR>")
    End if

    Else
    response.write("<h1>Unauthorized Password</h1><br><BR>Please call 800-381-0053 and ask for an available Account Executive to assist you.<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>")

    End if
    conn.close()
    set conn = nothing
    End if

  4. #4
    Join Date
    Oct 2005
    Posts
    1
    Do you have the form on the same page posting back to itself? If so, then you've got it inserting on page load and then again on the form post.

  5. #5
    Join Date
    Aug 2005
    Posts
    18

    Fixed!

    My problem was the form posting the information was using an input "image" type which does not require an onclick=submit(). I had both so it was submitting twice. I appreciate the help.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles