For Each item In request.form.. Code assistance

Results 1 to 2 of 2

Thread: For Each item In request.form.. Code assistance

  1. #1
    Wizzzard Guest

    Default For Each item In request.form.. Code assistance

    Earlier i posted a message regarding building an SQL insert statment the amount of times there are form items be parsed.<BR><BR>I am not getting any errors back but my code is not doing the task of insering the data. Can anybody spot where I am going wrong?<BR><BR>&#060;%Response.expires = 0<BR> Dim intItemCount <BR> Dim arFormValue()<BR> Dim strValue<BR> <BR> Dim objConn<BR> Dim objRS<BR> Dim strConn<BR><BR> set objConn = server.createObject("ADODB.Connection")<BR> strConn = connString<BR> objConn.Open strConn<BR> <BR> For Each item In request.form <BR> intItemCount = intItemCount + 1<BR> next<BR><BR> redim arFormValue(intItemCount)<BR><BR> x = 0<BR> For Each item In request.form<BR> strValue = Request.Form.Item(item)<BR> arFormValue(x) = strValue<BR> x = x + 1 <BR> Next<BR><BR> For x = 0 To (intItemCnt - 1)<BR> Response.write "INSERT INTO result(answer_id) Values(&#039;" & arFormValue(x) & "&#039;)"<BR> next<BR> <BR> objConn.close<BR> set objConn = nothing<BR> <BR>%&#062;

  2. #2
    Join Date
    Dec 1969

    Default Wow! Are you working too hard!

    Why do *THREE* loops, when *ONE* would do the job???<BR><BR>&#060;%<BR>For Each item In Request.Form<BR>&nbsp; &nbsp; conn.Execute( "INSERT INTO result(answer_id) Values(&#039;" & Request.Form(item) & "&#039;)" )<BR>Next<BR>%&#062;<BR><BR>Of course, one thing you need to realize is that *EVERY* field on the form gets processed *identically* the same way with this code...EVEN THE SUBMIT BUTTON if it is named in the form.<BR><BR>If you *insist* on transferring the form data to an array for some reason, then why not:<BR><BR>&#060;%<BR>Dim ar()<BR>ReDim ar( Request.Form.Count - 1 )<BR>cnt = 0<BR>For Each Item In Request.Form<BR>&nbsp; &nbsp; ar( cnt ) = Request.Form(Item)<BR>&nbsp; &nbsp; cnt = cnt + 1<BR>Next<BR>%&#062;<BR><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