Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I insert muliple selected values in a listbox into a database?

Status
Not open for further replies.

sbishops

Programmer
Dec 16, 2003
14
0
0
US
I am hand-coding (no FrontPage or Dreamweaver) an ASP, VBScript, JavaScript, MS Access 2000 dynamic web site.

Here are some code excerpts:

form1.asp
<label>Please enter name:
<input name = &quot;deliName&quot; type = &quot;text&quot;>
</label>
Please select all sandwiches that you make:
<select name = &quot;sandTypes&quot; multiple size = &quot;1&quot;>
<option>Reuben</option>
<option>PBJ</option>
<option>Grilled Cheese</option>
<option>BLT</option>
</select>
//End form1.asp


submitform.asp (Assume DB connection and rest of page works)
<%
Dim shopName, sandwichTypes
shopName = Request.Form(&quot;deliName&quot;)
sandwichTypes = ?????????????????
SQL = &quot;INSERT INTO DeliTable (name) VALUES('&quot; & shopName & &quot;')&quot;
SQLTWO = &quot;INSERT INTO SandTable (?????) VALUES (??????)&quot;
'End submitform.asp
%>

I just need to know how to GET ALL selected items from form1.asp, PUT them into an array, TEST against database field headers and finally send a YES or NO indicator to each sandwich field (Hopefully NO can be set as default).

I could use checkboxes, but my application is much larger and the user would get annoyed at having to check as opposed to highlighted selected items.

Database tables:
DeliTable:
deliID | deliName | etc....

SandTable:
deliID | Reuben | PBJ | Grilled Cheese | BLT |
1 yes no yes yes
2 no yes yes no

Thanks
(I hope the format of my tables comes thru enuf to see goal.
 
you will need to retrieve all the values seperately

<%
for i=1 to Request.Form(&quot;sandTypes&quot;).Count
Response.Write(Request.Form(&quot;sandTypes&quot;)(i) & &quot;<br />&quot;)
next
%>

and update accordingly
 
Thank you so much- I can't tell you how that's helped. Now can you tell me what the INSERT syntax would be and how i can test each item selected against an existing database field header (column name).

Do I have to use case statements or if-else statements and test each item against every single column name?

Like:
<%
for i=1 to Request.Form(&quot;sandTypes&quot;).Count
while(there are MS Access column names)
{
if(Request.Form(&quot;sandTypes&quot;)(i))== MS Access Column Name)
MS Access Field == &quot;Yes&quot;
else
MS Access Field == &quot;No&quot;
}

next
%>

Sorry for the C++ influence, old pseudocode habits are hard to break and this VBScript is new to me.
Can you see what I'm trying to accomplish and help me code in with correct syntax?

Thanks again sooooo much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top