Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP requestform Values And SQL DB

    I'm trying to set up a form that checks an SQL database to make sure that the team_name = request.form("team_name") does not already exist in the DB. The form submits to itself, checks the value in the database and if the team_name value exists the form reloads with the values filled in from the previous submit <%=team_name%>. The values are not being picked up (i'm losing them when i connect to the database)

    Here is the code to connect to the database, with a two response.redirect
    1) if form not okay, response.redirect="http://somesite.com/Team_RegistrationERROR.asp"

    2) if form okay,
    Response.Redirect "http://somesite.com/Team_CCpayment.asp" --values carry over to this page.

    The values for the fileds are being lost on the redirect.

    Can someone please help me out with the below ASP code?

    Connect to DB Code
    Code:
    <%
    team_name = request.form("team_name")
    capfname = Request.Form("cap_fname")
    caplname = Request.Form("cap_lname")
    address1 = Request.Form("address1")
    address2 = Request.Form("address2")
    city = Request.Form("city")
    state = Request.Form("state")
    zip = Request.Form("zip")
    phone = Request.Form("phone")
    email = Request.Form("email")
    ataNum = Request.Form("ataNum")
    ataAvg = Request.Form("ataAvg")
    ataYard = Request.Form("ataYard")
    %>
    <%
    team_name = request.form("team_name")
    capfname = Request.Form("cap_fname")
    caplname = Request.Form("cap_lname")
    address1 = Request.Form("address1")
    address2 = Request.Form("address2")
    city = Request.Form("city")
    state = Request.Form("state")
    zip = Request.Form("zip")
    phone = Request.Form("phone")
    email = Request.Form("email")
    ataNum = Request.Form("ataNum")
    ataAvg = Request.Form("ataAvg")
    ataYard = Request.Form("ataYard")
    %>
    <%
    'if problem, continue without throwing error code
    'take this out to receive debug msgs
    'on error resume next
    'Dim Connect to SQL Server Str
    Dim connection, sSQL, sConnString, oRS, oConn
    Dim connectstr, fieldname, tablename
    Dim db_name, db_username, db_userpassword
    Dim db_server
    Dim checkConn,countrec,check_qry,check_connectstr,checkRS
    
    'last chance to check for prop vals so strain off blank spaces in POST URL
    team_name = left(Trim(Replace(Request.Form("team_name"),"'","''")),40)
    capfname = left(Trim(Replace(Request.Form("cap_fname"),"'","''")),40)
    caplname = left(Trim(Replace(Request.Form("cap_lname"),"'","''")),40)
    address1 = left(Trim(Replace(Request.Form("address1"),"'","''")),40)
    address2 = left(Trim(Replace(Request.Form("address2"),"'","''")),40)
    city = left(Trim(Replace(Request.Form("city"),"'","''")),40)
    state = left(Trim(Replace(Request.Form("state"),"'","''")),40)
    zip = left(Trim(Replace(Request.Form("zip"),"'","''")),40)
    phone = left(Trim(Replace(Request.Form("phone"),"'","''")),40)
    email = left(Trim(Replace(Request.Form("email"),"'","''")),40)
    ataNum = left(Trim(Replace(Request.Form("ataNum"),"'","''")),40)
    ataAvg = left(Trim(Replace(Request.Form("ataAvg"),"'","''")),40)
    ataYard = left(Trim(Replace(Request.Form("ataYard"),"'","''")),40)
    
    if team_name <> "" THEN
    
    	'check to see if e-mail ADDY is already there
    	check_qry = "select * from teamtrap where ([team_name]) like ('" & _
    	team_name & "')" 
    
    	DBConnectionTwunk()
    	check_connectstr = "Driver={SQL Server};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_username & ";PWD=" & db_userpassword
    
    Set checkConn = Server.CreateObject("ADODB.Connection")
    	checkConn.Open check_connectstr
    	countrec=0
    	Set checkRS = checkConn.Execute(check_qry)
    	if not checkRS.EOF then
    		while not checkRS.EOF
    			countrec=countrec+1
    			checkRS.movenext
    		wend
    		checkRS.close
    	end if
    	Set checkRs = nothing
    	Set checkConn = nothing
    
    	if countrec > 0 then			
    			'If Rec Found then Throw Dupe E-Mail Error Page
    
    			Response.Redirect "http://somesite.com/Team_RegistrationERROR.asp" 
    
    else
    	'Else Throw Error Pg if Prob
    	Response.Redirect "http://somesite.com/Team_CCpayment.asp"
    end if
    end if
    	
    
    Function DBConnectionTwunk()
    'Routine makes SQLServer DB Conn
    	db_server = "somesite.net"
    	db_name = "DB_name"
    	db_username = "username"
    	db_userpassword = "12345"
    	fieldname = "fieldname"
    	tablename = "tablename"
    End Function
    %>

    FORM Code, autofilled with values. The values should carry over to the CC_Payment Page
    Code:
    <form action="Team_RegistrationERROR.asp" method="post" name="formname" id="formname" onsubmit="return checksubmit()">
    
                            <input name="team_name" type="hidden" id="team_name" value="<%=team_name%>" />
                           
                  </form>

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    ok. 3 things.

    1. In that first ASP code chunk you posted, the second 13 lines (excluding the ASP code delimiters) are EXACTLY the same as the first 13 lines. They populate the same variables with the same values. You don't need them.

    2. These bits:

    %>
    <%

    You don't need that, either. You're saying "ok, stop processing this as ASP... ok, start processing this as ASP" - without doing anything else in between. Not only is it a waste of your time, it slows the ASP processor down.

    3. A response.redirect() sends a response back to the client, that simply tells it to make a fresh request for the specified page. It doesn't include any form values or anything. You might find that server.transfer() is more useful in sending form values from one ASP page to another without sending a response back to the client in between.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An alternative is to use the querystring to hold the variables.
    This would be ok as long as you are not submitting important data such as passwords.

  • #4
    New Coder
    Join Date
    Aug 2004
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks to you both, I'll give a go and let you know if it works.

  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts
    instead of using response.redirect (provided the page is in the same site and not an external site) try using server.transfer
    The Transfer method sends (transfers) all the state information (all application/session variables and all items in the request collections) created in one ASP file to a second ASP file.


  •  

    Posting Permissions

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