help upload file

liunx

Guest
Hi,
I am very frustrated and have no more patience for this.. please help.

I am uploading a file and the code for uploading is fine, but I am trying to incorporate code to take the name and a path of the uploaded file and write it to a field in a database for a specific record.

I am having trouble reading and passing the chosen value (ID of the record)to a variable to later be used in my SQL statement to bring up the correct record.

I have two files 1)builds a form to take in file and 2)writes file to server and this is where I want to write to DB.

Here is some of my code:
I am trying to use java script function to read the chosen ID from form... but it looks like i am having trouble either with my logic or syntax.

PLEASE HEEEEELLLPPP!!!

Form:
<script language="JavaScript">
function getID ()
{
var ID
ID = document.getdata.cboJobNumber.value;
return ID;
};
</script>
<FORM METHOD="post" ENCTYPE="multipart/form-data" ACTION="upload.asp?ID =" & JobID=getID() name="getdata">
<div align="center">
<p><b>Select Job Number</b>
<select name="cboJobNumber" size="1">
<option selected>Choose from list</option>
<%
'create database object and open a connection
set objDB = Server.CreateObject("ADODB.Connection")
objDB.Open "DSN=MYDSN"
'create recordset objects and query the tables
set objRS = Server.CreateObject("ADODB.Recordset")
'this recordset is used to populate combo box with job numbers
objRS.Open "SELECT tblDTJobRequests.*, tblDTJobRequests.JobNumber FROM tblDTJobRequests WHERE (((tblDTJobRequests.JobNumber) Is Not Null)) ORDER BY tblDTJobRequests.JobNumber", objDB, adOpenKeyset, adLockOptimistic, adCmdText


DO WHILE NOT objRS.EOF
Response.Write "<option value="""
Response.Write objRS("JobReqId")
Response.Write """>"
Response.Write objRS("JobNumber")& "</option>"
Response.Write " "

objRS.MoveNext
LOOP

%>
</select>
</p>
<p><b>File1 :</b>
<INPUT TYPE="file" NAME="file1">
<BR>
<b>File2 : </b>
<INPUT TYPE="file" NAME="file2">
<BR>
<b>File3 : </b>
<INPUT TYPE="file" NAME="file3">
<BR>
<b>File4 : </b>
<INPUT TYPE="file" NAME="file4">
<BR>
<b>File5 : </b>
<INPUT TYPE="file" NAME="file5">
<BR>
<INPUT TYPE="submit" NAME="Enter" value=" Upload ">
</p>
</div>
<%objRS.Close
set objRS = Nothing
objDB.Close
set objDB = Nothing%>
</FORM>

Here is my processing:

varJobID = request("ID")

Response.Write "This is Job ID: " & request("ID")

byteCount = Request.TotalBytes
RequestBin = Request.BinaryRead(byteCount)
Dim UploadRequest
Set UploadRequest = CreateObject("Scripting.Dictionary")
BuildUploadRequest RequestBin

dim objDBid
dim objRSid

set objDBid = Server.CreateObject("ADODB.Connection")
objDBid.Open "DSN=DTJobReq"
set objRSid = Server.CreateObject("ADODB.Recordset")
'this recordset is used to get record with selected job numbers
objRSid.Open "SELECT * FROM tblDTJobRequests WHERE [JobReqID]= " & varJobID, objDBid, adOpenKeyset, adLockOptimistic, adCmdText

'file 1
contentType = UploadRequest.Item("file1").Item("ContentType")
filepathname = UploadRequest.Item("file1").Item("FileName")
filename = Right(filepathname,Len(filepathname)-InstrRev(filepathname,"\"))
if not filename="" then
value = UploadRequest.Item("file1").Item("Value")
Set ScriptObject = Server.CreateObject("Scripting.FileSystemObject")
Set MyFile = ScriptObject.CreateTextFile("\\server\folder\files\" & filename)
For i = 1 to LenB(value)
MyFile.Write chr(AscB(MidB(value,i,1)))
Next

'write name of file to job number record of database
objRSid("AttachedFile1") = "\\server\folder\files\" & filename
objRSid.Update

MyFile.Close
set myfile = nothing
 
Back
Top