Welcome to WebmasterWorld Guest from 54.144.107.83

Forum Moderators: ocean10000

Message Too Old, No Replies

Classic ASP - getting multiple values for update

     
10:35 pm on Oct 15, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 58
votes: 0


Hi,

I'm working with a form that has fields for updating several different tables. I'm currently trying to get a drop down and a textarea to insert into a new row in the same table.
I've started writing the code below to 'link' the drop down and the text area in order to put them both into the insert statement. My question is...is there a better, more efficient way to do this?

Thanks for any help!




For each item in Request.Form

strOuterItems = strOuterItems & item & "_" & Request.Form(item) & "|"


strInnerItems = strInnerItems & item & "_" & Request.Form(item) & "|"



Next

arrOuterItems = split(strOuterItems,"|")

arrInnerItems = split(strInnerItems,"|")



for i=0 to UBound(arrOuterItems)

for j=0 to UBound(arrInnerItems)


if Left(arrOuterItems(i),13)="strObjNum_js_" Then

arrOuterItems(i)=replace(arrOuterItems(i),"strObjNum_js_","")


If Left(arrInnerItems(j),14)="strObjDesc_js_" Then

arrInnerItems(j)=replace(arrInnerItems(j),"strObjDesc_js_","")


If Left(arrOuterItems(i),1)=Left(arrInnerItems(i),1) Then


a=Split(arrOuterItems(i),"_")
b=Split(arrInnerItems(i),"_")

myArrayCount=0

for each x in a
If myArrayCount=0 then
strObjIndex=a(myArrayCount)
End If
If myArrayCount=1 then
strObjNum=a(myArrayCount)
End If

myArrayCount=myArrayCount+1
next

myArrayCount=0

for each x in b
If myArrayCount=0 then
strObjIndex=b(myArrayCount)
End If
If myArrayCount=1 then
strObjDesc=b(myArrayCount)
End If

myArrayCount=myArrayCount+1
next

End If


End If

end if

next

next
2:51 am on Oct 18, 2010 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


Why are you converting from a collection --> string --> Array?

You can run though the form collection a great deal easier, with less chance of having a injection style attack played against your site.
2:02 pm on Oct 18, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 58
votes: 0


Well, I have a form in which only certain elements will be used for inserting to/updating certain tables. I have named each according to the table which will be updated, so that a string for the sql can be formed.

I have a drop down and a textarea for each db table, and I need to 'associate' each pair to do the sql. For example (where 'strObjNum' is the data from the dropdown and 'strObjDescr' is the data from the textarea:

Insert into StrategicPlanObjective (ObjectiveNumber, ObjectiveDescription) Values (strObjNum, strObjDescr); 


Would I need to have a nested loop situation to get the two together for the SQL (above)? If so, can I do nested loops through the form collection?

Thanks
2:42 pm on Oct 18, 2010 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


Are the fields uniquely named? If they are you just have to do the following. Which is a great deal easier to understand then trying to figure out exactly what the nested for loops are doing.

value = Request.Form["unique Name1"]
value = Request.Form["unique Name2"]
3:03 pm on Oct 18, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 58
votes: 0


Thanks - they are uniquely named, but some need to go to tableA, some to tableB, some to tableC, etc.

Yes, it's easy enough to assign the values to variables, but getting the variables that go to the same tables (same SQL) is what I'm trying to do.

Thanks again.
5:30 pm on Oct 18, 2010 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


So what you need to do is map the Unique variables to the correct tables. And some of the variables might be used in multiple tables.

I just going to rough draft function as example code, which I hope might make it easier to visualize.

Update_Table1(uniqueName1,uniqueName2,uniqueName3)
Update_Table2(uniqueName1,uniqueName5,uniqueName6)
Update_Table3(uniqueName1,uniqueName7,uniqueName8)

Each Update Method would update a separate table, and can share the same variables. All the while of keeping things nice and neat.
6:42 pm on Oct 18, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 58
votes: 0


Thanks - that's a good idea.
I need to also mention that there is a possibility for multiples in the same columns.

For example, there could be more than one Objective text box, and each of those text boxes would update the Objective database table.

The same possibility applies to the other columns. I have appended the dropdown and textarea names with a 'count' variable in order to give them each a distinct name and id.

Would this idea still work when there are multiple variables possible (the exact number of which unknown)?

Thanks
5:49 pm on Oct 19, 2010 (gmt 0)

Administrator

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
posts:852
votes: 0


The functions would be generic, that you can pass them data, the only thing would change is the variables you pass them. So as long as you can keep your variables straight, it will work.
1:34 pm on Oct 21, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 58
votes: 0


Thanks - my main question, however, lies perhaps in the naming of the form objects to keep them unique.
I've been using a GUID (generated by ASP) in a hidden form field to update the tables; however, I don't want the GUID to be visible in the source code. Firebug, for example, will reveal the hidden values quite easily. Is there an alternative so that the GUID won't be visible?

Thanks
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members