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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Select not sending all selected items to DB

Status
Not open for further replies.

bhewi

Programmer
Dec 16, 2003
12
US
I have a multi select form that retrieves a list of users from a database and upon clicking on them moves them from the left box to the right box. I then want to upload a file and a description of the file up to the database (access) for each user. I have everything working except when I select more than one user it only uploads the first one on the list. I fairly new at this so any help would be really appreciative.

Thanks
Bryon

Here is the code from the form:

<FORM NAME=&quot;userslist&quot; METHOD=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot;
ACTION=&quot;ado_upload.asp?<% = PID %>&quot;
OnSubmit=&quot;return ShowProgress();&quot;>

<CENTER>
<TABLE border=1>
<TR><TD>
<table>
<tr>
<td bgcolor=&quot;#cccccc&quot; align=&quot;middle&quot; ><b>Available Users</b></td>
<td></td>
<td bgcolor=&quot;#cccccc&quot; align=&quot;middle&quot; ><b>Selected Users</b></td>
</tr>
<tr>
<td align=&quot;left&quot;><!-- onchange=&quot;moveit();&quot; -->
<select name=&quot;menuitems1&quot; onchange=&quot;moveit();&quot; style=&quot;WIDTH: 300px&quot; size=&quot;10&quot; multiple>
<%
'Loop through the recordset adding each customer to the combo box
Do While Not objRS.EOF
%>
<option value=&quot;<%=objRS(&quot;UserName&quot;)%>&quot;>
<%=objRS(&quot;CustName&quot;)%> -- <%=objRS(&quot;CompanyName&quot;)%></option>

<%
objRS.MoveNext
Loop

'Close and dereference database objects
objRS.Close
Set objRS = Nothing
%>

</select>
</td>
<td align=&quot;middle&quot;>
<input type=&quot;button&quot; tagName=&quot;BUTTON&quot; onclick=&quot;removefromcombo();&quot; value=&quot; < < Remove&quot; id=&quot;submit2&quot; name=&quot;submit2&quot; style=&quot;FONT-WEIGHT: bold&quot;>
</td>
<td align=&quot;left&quot;>
<select name=&quot;UserName&quot; id=&quot;UserName&quot; style=&quot;WIDTH: 300px&quot; size=&quot;10&quot; multiple>

</select></td></tr><tr><td colspan=&quot;3&quot;>

File:  <INPUT TYPE=FILE NAME=&quot;THEFILE&quot; size=&quot;20&quot;></p>
<P>
Description:  <TEXTAREA NAME=&quot;DESCR&quot; rows=&quot;1&quot; cols=&quot;31&quot;></TEXTAREA><P>
<INPUT TYPE=SUBMIT VALUE=&quot;Upload!&quot;></FORM>

----------------------------------
Here is the code from the page that places the data in the DB:
<%
Set Upload = Server.CreateObject(&quot;Persits.Upload&quot;)
Upload.ProgressID = Request.QueryString(&quot;PID&quot;)

' we use memory uploads, so we must limit file size
Upload.SetMaxSize 40000000, True

' Save to memory. Path parameter is omitted
Count = Upload.Save

' Obtain file object
Set File = Upload.Files(&quot;THEFILE&quot;)

If Not File Is Nothing Then

Connect = &quot;DSN=aspupload&quot;

' Use ADO Recordset object
Set rs = Server.CreateObject(&quot;adodb.recordset&quot;)

' Reopen recordset to insert file
rs.Open &quot;MYIMAGES&quot;, Connect, 2, 3

rs.AddNew
rs(&quot;image_blob&quot;) = File.Binary
rs(&quot;filename&quot;) = File.FileName
rs(&quot;filesize&quot;) = File.Size
rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
rs(&quot;UserName&quot;) = Upload.Form(&quot;UserName&quot;)
rs.Update

Response.Write &quot;File saved.&quot;
Else
Response.Write &quot;File not selected.&quot;
End If
%>
 

you will need to retrieve all the values seperately

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

and update accordingly
 
Where does that code need to go though. I think I understand what it does but I guess I'm not real clear on where it goes and in which page. Thanks for any help you can offer.

Bryon
 

I have had no dealing with your upload dll so not sure what it does - however this should create a new database entry for each user / file

for i=1 to Request.Form(&quot;UserName&quot;).Count
rs.AddNew
rs(&quot;image_blob&quot;) = File.Binary
rs(&quot;filename&quot;) = File.FileName
rs(&quot;filesize&quot;) = File.Size
rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
rs(&quot;UserName&quot;) = Request.Form(&quot;UserName&quot;)(i)
rs.Update
next

hope this helps

Simon

 
Where you have:
Code:
        rs.AddNew
        rs(&quot;image_blob&quot;) = File.Binary
        rs(&quot;filename&quot;) = File.FileName
        rs(&quot;filesize&quot;) = File.Size
        rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
        rs(&quot;UserName&quot;) = Upload.Form(&quot;UserName&quot;)
        rs.Update

Do this:
Code:
        rs.AddNew
        rs(&quot;image_blob&quot;) = File.Binary
        rs(&quot;filename&quot;) = File.FileName
        rs(&quot;filesize&quot;) = File.Size
        rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
        For i=1 To Request(&quot;UserName&quot;).Count
            If (i > 1) Then
                rs(&quot;UserName&quot;) = rs(&quot;UserName&quot;) & &quot;,&quot;
            End If
            rs(&quot;UserName&quot;) = Request(&quot;UserName&quot;)(i)
        Next
        rs.Update

Take Care,
Mike
 
I am getting this error message after submitting the form. Any clue what it means?

Request object error 'ASP 0208 : 80004005'

Cannot use generic Request collection

/xtransfer2/ado_upload.asp, line 70

Cannot use the generic Request collection after calling BinaryRead
 
Actually, I take back my above suggestion. Try the following code to test what you get back:
Code:
<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<html>
	<head>
	</head>
	<body>
		Result: <%= Request(&quot;test&quot;) %><br><br><br>
		<form method=&quot;post&quot;>
			<select name=&quot;test&quot; multiple>
				<option>test1</option>
				<option>test2</option>
				<option>test3</option>
				<option>test4</option>
			</select>
			<input type=&quot;submit&quot; value=&quot;submit&quot;>
		</form>
	</body>
</html>

This means that your initial ASP code should be:
Code:
        rs(&quot;image_blob&quot;) = File.Binary
        rs(&quot;filename&quot;) = File.FileName
        rs(&quot;filesize&quot;) = File.Size
        rs(&quot;description&quot;) = Request(&quot;DESCR&quot;)
        rs(&quot;UserName&quot;) = Request(&quot;UserName&quot;)
        rs.Update

Take Care,
Mike
 
Mike,

The problem is that it is a multiple select drop down - so you need to iterate through the results.

bhewi,

what is this line?

/xtransfer2/ado_upload.asp, line 70
?

Simon
 
simonchristieis,
the multi-select is a comma-separeted list of values, its not passed as an array, so it can't be iterated through.

Try my test code. ;)

Take Care,
Mike
 
Line 70 is this:

For i=1 To Request(&quot;UserName&quot;).Count

I am making the test page right now as well.

 
Mike,
Im listening, I don't wanna argue ;) - my code just seperates the values - the problem here is

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

As for the error - i just googled the error code and it suggests replacing 'Request.Form' with 'UploadFormRequest'
 
Simon,

Here is what it said when I used the UploadFormRequest:



Microsoft VBScript runtime error '800a000d'

Type mismatch: 'UploadFormRequest'

/xtransfer2/ado_upload.asp, line 64

Michael,

I did your test code and it gave me an idea .... I'm going to tweak it a little and try something.
 
simonchristieis,

Right, didn't mean to butt heads :). Here's what I'm thinking:

Since Request(&quot;UserName&quot;) is actually a string, and not a collection, the .Count method won't work here.

Take Care,
Mike
 
Well since you using the form for uploading some data then you cant Access the Request.Form object only Request.QuerryString.

But your upload component gives you the Uploader.Form collection wich will contains the data you need.

So i woul try this way

<select name=&quot;menuitems1&quot;...
<select name=&quot;UserName&quot;... are multiple values
you shoudl Response.Write theyr values

Response.Write Upload.Form(&quot;DESCR&quot;)
Response.Write Upload.Form(&quot;UserName&quot;)
Response.Write Upload.Form(&quot;menuitems1&quot;) and see if they are ok
If they are OK then it shoudl work.

________
George, M
 

I tried to dumb down the form a bit and try your Michael's test code but I ended up with an older problem I was having yesterday. So I'll go back to the one I was working on earlier this morning. Which brings me back to the same problem I was having earlier which is:

It is only uploading the values for the top user on the list.
 
Shaddow,

I tried what you said and it uploaded just the file, file name, and file size. It also just printed the Description and username to the results page. I used this code:

rs.AddNew
rs(&quot;image_blob&quot;) = File.Binary
rs(&quot;filename&quot;) = File.FileName
rs(&quot;filesize&quot;) = File.Size
Response.Write Upload.Form(&quot;DESCR&quot;)
Response.Write Upload.Form(&quot;UserName&quot;)
Response.Write Upload.Form(&quot;menuitems1&quot;)
rs.Update
 
Clarfications:
Not able to use Request Collection: The reason you couldn't access the Request collection is because when you tell it you are going to be reading the data as binary data (automatic part of doing a BinaryRead) then it converts it binary internally and does not re-populate the Request collection. Thus you have to hope that whoever made your upload component decided to store that data internally for you to access. This is what is happening when you say Upload.Form(&quot;value&quot;). Basically your gettig the values that used to be in the Request.Form collection.

Iterating Through Request Collection: If you have multiple values with the same name you can retrieve these as a comme-delimited string by simply calling Request.Form(&quot;fieldname&quot;)

or you can iterate through them using a For Each loop. Both of these methods are valid and the for each has the additional bonus of not geting confused by any user enetered commas. Just through I should hit on that since there was some confusion earlier.


Question: I understand that your using multiple select's now, but I haven't seen anyone mention whether the values you want o pass are actually selected in the multiple select before you submit the form. If they are just in the select box, but not selected than they will not be passed, only the selected one will be passed. This might be the reason you were only seeing a single results earlier. If this is the case than you may want to add a function that loops through all of the options in that selection and makes them all selected. You could call this funtion in the onSubmit for the form before your other function call.

If that isn't an issue (or if it is and once you have finished) you can use the values that shaddow had you Response.Write and place them in the records. He was just showing you how to test if Upload.Form(&quot;&quot;) would retrieve them for you. Now that you know how to get access to thenm you can use them to enter into the recordset.

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
A I see what Shaddow was saying. I used the following code to see what was being returned. When I did that I saw that it is only submitting the first one on the multiple select list, Which means if I select two it is ignoring the second one as if I didn't upload anything to that individual. I don't know if this can help any but the URL to see what I am doing is This may be a dumb question but is it possible to loop through the following code until there are no records left to input into the database?:

rs.AddNew
rs(&quot;image_blob&quot;) = File.Binary
rs(&quot;filename&quot;) = File.FileName
rs(&quot;filesize&quot;) = File.Size
' rs(&quot;hash&quot;) = Hash
rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
rs(&quot;UserName&quot;) = Upload.Form(&quot;UserName&quot;)
rs.Update

Response.Write Upload.Form(&quot;UserName&quot;)
Response.Write Upload.Form(&quot;menuitems1&quot;)
Response.Write &quot;File saved.&quot;
Else
Response.Write &quot;File not selected.&quot;
End If
 
I'm surprised that your getting any value because your script keeps resetting the selected index to -1 (ie, nothing selected). What you need to do is create a script to loop through all the options and make them all selected before the form submit occurs, this way they will all get passed (only the selectedoptions are passed to the next page).

-T

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
The never-completed website:
 
Does the FAQ entitled &quot;Linked List Boxes without Reloading Page&quot; have an example or the code needed to loop through the selected items in the multiselect list? I'm having some difficult finding something out there like this.

Bryon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top