SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Feb 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirect Problem

    All,
    I have asp code below. I also have a redirect piece at the end of the code that is not doing like I want it to do. If the refresh button is clicked or if someone is coming straight to my submission page, it automatically redirects to the confirmation page, which is not what I want. I only want the redirect to happen after a successful submission.

    Can anyone help me with this problem?

    <%
    ConnString = "Driver={MySQL};SERVER=localhost;DATABASE=gsgevents ;UID=gsgevents;PASSWORD=mollycollie"
    Set Conn = Server.CreateObject("ADODB.Connection")
    Conn.Open ConnString

    mySQL = "INSERT INTO tbl_registration (dateEntered,salutation,first_lastName,company,mai lingAddress,city,state,zipCode,telephoneNo,faxNo,e mailAddress,xMeal,hotelYesNo,arrivalDate,departure Date,roomType,bedSize,sharingRoomYesNo,roomMate,to talInRoom,creditCardType,creditCardNo,cardHoldersN ame,expDate)"
    mySQL = mySQL & " VALUES ('" & request.form("dateEntered") & "','" & request.form("salutation") & "','" & request.form("first_lastName") & "','" & request.form("company") & "','" & request.form("mailingAddress") & "','" & request.form("city") & "','" & request.form("state") & "','" & request.form("zipCode") & "','" & request.form("telephoneNo") & "','" & request.form("faxNo") & "','" & request.form("emailAddress") & "','" & request.form("xMeal") & "','" & request.form("hotelYesNo") & "','" & request.form("arrivalDate") & "','" & request.form("departureDate") & "','" & request.form("roomType") & "','" & request.form("bedSize") & "','" & request.form("sharingRoomYesNo") & "','" & request.form("roomMate") & "','" & request.form("totalInRoom") & "','" & request.form("creditCardType") & "','" & request.form("creditCardNo") & "','" & request.form("cardHoldersName") & "','" & request.form("expDate") & "')"
    'make sure to change the word "demoConn"
    'below to the name of your connection
    Conn.execute(mySQL)

    Response.Redirect ("http://www.gsgevents.com/secureEvents/confirmation.html")
    %>

  2. #2
    A Smarter Way to Web! zivo's Avatar
    Join Date
    Aug 2003
    Location
    Chicago
    Posts
    433
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb Thoughts on pieces of it

    Hi... I am assuming there is more to the Web page than this?

    One approach to take is when submitting a form to itself (the same page) that you put a querystring value in the URL. Then to get to the logic to insert and redirect, you check for the existence of the querystring. Hidden form field values also work.

    Good luck.

    mp/m

  3. #3
    SitePoint Addict danfran's Avatar
    Join Date
    Jan 2005
    Location
    New York City
    Posts
    244
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One way you could do it is to issue another SQL statement following the INSERT that tries to SELECT the record that you just inserted. If you find it, then response.redirect. If not, then continue loading the page.

    I'm not sure how your application works, but you'd have to find some way to SELECT the record you inserted by combining enough pieces of data to make your selection unique. (What is unique about the data entered? email address? -maybe combination of email / datetime?)

    Don't forget that this script could be run almost simultaneously by many, many users.. DO NOT select the max(WhateverID) to accomplish this!!

    Dan

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks as though an autoincrement number is used since I see no ID anywhere...since using MySQL I do believe you use the LAST_INSERT_ID() function. If this is true (I am not too knowledgable on MySQL) then perhaps the following would work after your insertion:


    confirmID = LAST_INSERT_ID()

    If isNumber(confirmID) AND NOT isNull(confirmID) Then

    Response.Redirect ("http://www.gsgevents.com/secureEvents/confirmation.html")

    Else



    'error blah

    End If



    not sure if it will work but good luck - Brian


Bookmarks

Posting Permissions

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