www.webdeveloper.com
Results 1 to 2 of 2

Thread: I must be seeing this wrong - please check

  1. #1
    Join Date
    Jan 2007
    Location
    Columbia, MD
    Posts
    45

    Question I must be seeing this wrong - please check

    I have this code that I know is right and I have checked it for hours BUT it results in the wrong values. Would you please look and see if I am blocking something out. I am trying to build up an SQL string for a database with values from a form and the values look right but the string is wrong.
    Here is the code:
    For i= 1 to count
    FoodPs = "FoodPs" & i
    Response.Write("<br>")
    Response.Write("Food is:")
    Response.Write(Session("FoodN")(i)) 'CORRECT
    Response.Write("<br>")
    Response.Write("Preference is:")
    Response.Write(request.form(FoodPs)) 'CORRECT
    Session("FoodP")(i) = request.form(FoodPs) 'here I put it in the array
    Response.Write("<br>")
    response.write("FoodPs name="& FoodPs)
    mSQL="INSERT INTO Foods("
    mSQL = mSQL & "Family,"
    mSQL = mSQL & "PersonID,"
    mSQL = mSQL & "Food,"
    mSQL = mSQL & "Preference)"
    mSQL = mSQL & "Values("
    mSQL = mSQL & "'" & Replace(Session("GuestID"),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(Session("Fcount"),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(Session("FoodN")(i),"'","''") & "', "
    mSQL = mSQL & "'" & Replace(Session("FoodP")(i),"'","''") & "')" ' ' HERE I USE THE ARRAY YET THE VALUE IS WRONG!
    Response.Write("<br>")
    Response.Write(mSQL) 'change this to execute
    mSQL = ""
    Next

    IT RESULTS IN THIS OUTPUT:
    Food is:tomato
    Preference is:3
    FoodPs name=FoodPs1
    INSERT INTO Foods(Family,PersonID,Food,Preference)Values('9', '1', 'tomato', '3')
    Food is:carrot
    Preference is:3
    FoodPs name=FoodPs2
    INSERT INTO Foods(Family,PersonID,Food,Preference)Values('9', '1', 'carrot', '2')
    The last number is '2' when it should be '3' because it is the same value " request.form(FoodPs)" which is put into a Session array,"Session("FoodP")(i)" because the request.form give an error when added to the string.

    THE URL IS HERE: http://kitchenkarate.com/members/Add...tegory=Produce

    THANKS IN ADVANCE TO ANYONE WHO TAKES A LOOK,
    PETER

  2. #2
    Join Date
    Jan 2007
    Location
    Columbia, MD
    Posts
    45

    resolved I figured it out

    After explaining that long post it made me think why am I using a session variable at all. I used a local variable and that did the trick. Sorry if you took time puzzling over this but writing it made me see the problem.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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