Request.Form using variables

Results 1 to 2 of 2

Thread: Request.Form using variables

  1. #1
    Join Date
    Dec 1969

    Default Request.Form using variables

    I&#039;m writing an update statement that is trying to match old info with its new information in SQL using this kind of array structure, if you can call it that. My problem is that when I perform the update, it only takes one of the values from the series and updates every record with that info from the form. On another note, is it ok to use variables in the Request.Form object, like:<BR>&#060;% <BR>Dim aname<BR>aname = "bob"<BR>Request.Form(aname)<BR>%&#062;<BR><BR>Any way, here is my code<BR><BR>For Each item In Request.Form<BR>If Left(item, 6 ) = "Option" Then<BR>Dim optionvalue,oldpoll,oldpolloption<BR>optionvalue = Request.Form(item)<BR>oldpoll = "oldpoll"<BR>oldpoll = oldpoll & Right(item, 2)<BR>oldpolloption = Request.Form(oldpoll)<BR> SQL = "UPDATE tbl_polloptions SET polloption =&#039;" + Replace(optionvalue, "&#039;","&#039;&#039;") + "&#039; WHERE poll_id =" & editpollid & " AND polloption =&#039;" + Replace(oldpolloption, "&#039;","&#039;&#039;") + "&#039;"<BR> rsUpdatePoll.CommandText = SQL<BR> Set rsUpdateOptions = rsUpdatePoll.Execute<BR>End If<BR>Next<BR><BR>All help is muchos appreciodos(Spanglish)<BR><BR>Dave

  2. #2
    Join Date
    Dec 1969

    Default Bill's mantra: DEBUG DEBUG DEBUG

    Of *course* you can use a variable with Request.Form. The Request.Form method has *NO IDEA* what kind of value you used to call it with. It just wants and receives a string, and it doesn&#039;t care where the string came from. You can even call with a Date/Time value and it will get auto-converted to string, for example.<BR><BR>That being said...<BR><BR>I don&#039;t see anything wrong with your logic, but who knows whether you are getting what you expect from the form fields????<BR><BR>Time to add DEBUG code!<BR><BR>AT A MINIMUM, add the Response.Write&#039;s I suggest here:<BR><BR>&#060;%<BR>...<BR>Dim optionvalue,oldpoll,oldpolloption<BR>For Each item In Request.Form<BR>&nbsp; &nbsp; If Left(item, 6 ) = "Option" Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; optionvalue = Request.Form(item)<BR>&nbsp; &nbsp; &nbsp; &nbsp; oldpoll = "oldpoll" & Right(item, 2)<BR>&nbsp; &nbsp; &nbsp; &nbsp; oldpolloption = Request.Form(oldpoll)<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "Processing item: " & item & "&lt;BR&#062;"<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "optionvalue: " & optionvalue & ", oldpolloption: " & oldpolloption & "&lt;BR&#062;"<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; ALWAYS USE & for string concatenation...NEVER +!!!!<BR>&nbsp; &nbsp; &nbsp; &nbsp; SQL = "UPDATE tbl_polloptions SET polloption =&#039;" & Replace(optionvalue, "&#039;","&#039;&#039;") _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; & "&#039; WHERE poll_id =" & editpollid _<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; & " AND polloption =&#039;" & Replace(oldpolloption, "&#039;","&#039;&#039;") & "&#039;"<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "SQL: " & SQL & "&#060;HR&#062;" & vbNewLine<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; Do *NOT* get a recordset! Executing UPDATE does not creat one!<BR>&nbsp; &nbsp; &nbsp; &nbsp; rsUpdatePoll.Execute( SQL )<BR>&nbsp; &nbsp; End If<BR>Next<BR>...<BR>%&#062;<BR>

Posting Permissions

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