homepage Welcome to WebmasterWorld Guest from 54.211.113.223
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Classic ASP - getting multiple values for update
buck1107

10+ Year Member



 
Msg#: 4217373 posted 10:35 pm on Oct 15, 2010 (gmt 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

 

Ocean10000

WebmasterWorld Administrator 10+ Year Member



 
Msg#: 4217373 posted 2:51 am on Oct 18, 2010 (gmt 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.

buck1107

10+ Year Member



 
Msg#: 4217373 posted 2:02 pm on Oct 18, 2010 (gmt 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

Ocean10000

WebmasterWorld Administrator 10+ Year Member



 
Msg#: 4217373 posted 2:42 pm on Oct 18, 2010 (gmt 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"]

buck1107

10+ Year Member



 
Msg#: 4217373 posted 3:03 pm on Oct 18, 2010 (gmt 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.

Ocean10000

WebmasterWorld Administrator 10+ Year Member



 
Msg#: 4217373 posted 5:30 pm on Oct 18, 2010 (gmt 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.

buck1107

10+ Year Member



 
Msg#: 4217373 posted 6:42 pm on Oct 18, 2010 (gmt 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

Ocean10000

WebmasterWorld Administrator 10+ Year Member



 
Msg#: 4217373 posted 5:49 pm on Oct 19, 2010 (gmt 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.

buck1107

10+ Year Member



 
Msg#: 4217373 posted 1:34 pm on Oct 21, 2010 (gmt 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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved