PDA

View Full Version : upload and insert.


Baleric
05-27-2006, 11:13 AM
hey guys,
i got a problem with inserting data and uploading a file, i got a form with a premade upload script and im trying to insert the filename along with a couple of textfields into an access DB, heres the problem im getting

Request object, ASP 0207 (0x80004005)
Cannot use Request.Form collection after calling BinaryRead.
/Shopping/Pages/adminadd.asp, line 106

i did a google search and it says to change the "request.form" to "UploadFormRequest" i cant get this working at all,

here is my code anyways if you would like a look,

<%


' ****************************************************
' Change the value of the variable below to the pathname
' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
Dim uploadsDirVar
uploadsDirVar = "d:/shopping/pages/productimages/"
' ****************************************************

' Note: this file uploadTester.asp is just an example to demonstrate
' the capabilities of the freeASPUpload.asp class. There are no plans
' to add any new features to uploadTester.asp itself. Feel free to add
' your own code. If you are building a content management system, you
' may also want to consider this script: http://www.webfilebrowser.com/

function OutputForm()

end function
%>




<%


function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
Err.Clear
testFile.Close
fso.DeleteFile(fileName)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
exit function
end if
Err.Clear
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
exit function
end if
Set streamTest = Nothing
end function


function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)


' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
next
else
SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
end if

end function
%>
<%
'declare your variables
dim connection
dim sSQL, sConnString
dim attach11
dim itemid
dim itemname
dim Yourprice
dim rrp
dim shipau
dim shipww
dim textfield1
dim textarea1


attach11 = savefiles
itemid1 = request.form("itemid")
itemname = request.form("itemname")
Yourprice = request.form("Yourprice")
rrp = request.form("rrp")
shipau = request.form("shipau")
shipww = request.form("shipww")
textfield1 = request.form("textfield")
textarea1 = request.form("textarea")


sSQL="INSERT INTO items (attach11, itemid1, itemname, Yourprice, rrp, shipau, shipww, textfield1, textarea1) VALUES ('"& Thumbnail &"', '"& CategoryID &"', '"& Product &"', '"& YourPrice &"', '"& RRP &"', '"& ShippingCostAU &"', '"& ShippingCostWRLD &"', '"& ProductInfo &"', '"& ExtraInfo &"' )"

sConnString = MM_AIRcart_STRING


Set connection = Server.CreateObject("ADODB.Connection")



connection.Open(sConnString)


connection.execute(sSQL)


Connection.Close
Set Connection = Nothings
%>

please help if you can

thanks in advance

baleric

Baleric
05-27-2006, 11:27 AM
sorry guys absolute stupid mistake i made,

all the insert is working now, but now i cant upload the file... wont let me

when i went into the original form for the upload script it was set the this encryption method,
enctype="multipart/form-data"

but i set it to nothing, or else it wouldnt insert my data,
is this the reason y the file is not uploding,
also is there a way to set the upload script to work with no encoding?

im stuck, this is far past my abilitys in asp

mehere
05-28-2006, 05:00 PM
you need enctype="multipart/form-data" if you plan on uploading files ... since you're using an upload script you have to use the equivalent of the request.form for the upload component you're using ... for this upload script you need to use Upload.Form("field_name") in order to get your other values.

Baleric
05-29-2006, 03:18 AM
you need enctype="multipart/form-data" if you plan on uploading files ... since you're using an upload script you have to use the equivalent of the request.form for the upload component you're using ... for this upload script you need to use Upload.Form("field_name") in order to get your other values.

when i use upload.form("") i get this error

Object Required "

and when i use UploadFormRequest("") i get this error

Type mismatch: 'UploadFormRequest'

i really need help, this is the final thing thats stopping me from my site going live..

thanks in advance

baleric

mehere
05-29-2006, 04:41 PM
post the current code that you're using ... i use this script and have no problem with using what i posted.

Baleric
05-30-2006, 07:04 AM
<%


' ****************************************************
' Change the value of the variable below to the pathname
' of a directory with write permissions, for example "C:\Inetpub\wwwroot"
Dim uploadsDirVar
uploadsDirVar = "d:/shopping/pages/productimages/"
' ****************************************************

' Note: this file uploadTester.asp is just an example to demonstrate
' the capabilities of the freeASPUpload.asp class. There are no plans
' to add any new features to uploadTester.asp itself. Feel free to add
' your own code. If you are building a content management system, you
' may also want to consider this script: http://www.webfilebrowser.com/

function OutputForm()

end function
%>

<%


function TestEnvironment()
Dim fso, fileName, testFile, streamTest
TestEnvironment = ""
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FolderExists(uploadsDirVar) then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not exist.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
fileName = uploadsDirVar & "\test.txt"
on error resume next
Set testFile = fso.CreateTextFile(fileName, true)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have write permissions.</B><br>The value of your uploadsDirVar is incorrect. Open upload.asp in an editor and change the value of uploadsDirVar to the pathname of a directory with write permissions."
exit function
end if
Err.Clear
testFile.Close
fso.DeleteFile(fileName)
If Err.Number<>0 then
TestEnvironment = "<B>Folder " & uploadsDirVar & " does not have delete permissions</B>, although it does have write permissions.<br>Change the permissions for IUSR_<I>computername</I> on this folder."
exit function
end if
Err.Clear
Set streamTest = Server.CreateObject("ADODB.Stream")
If Err.Number<>0 then
TestEnvironment = "<B>The ADODB object <I>Stream</I> is not available in your server.</B><br>Check the Requirements page for information about upgrading your ADODB libraries."
exit function
end if
Set streamTest = Nothing
end function


function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey

Set Upload = New FreeASPUpload
Upload.Save(uploadsDirVar)


' If something fails inside the script, but the exception is handled
If Err.Number<>0 then Exit function

SaveFiles = ""
ks = Upload.UploadedFiles.keys
if (UBound(ks) <> -1) then
SaveFiles = "<B>Files uploaded:</B> "
for each fileKey in Upload.UploadedFiles.keys
SaveFiles = SaveFiles & Upload.UploadedFiles(fileKey).FileName & " (" & Upload.UploadedFiles(fileKey).Length & "B) "
next
else
SaveFiles = "The file name specified in the upload form does not correspond to a valid file in the system."
end if

end function
%>

<% If request.QueryString("insert") = 2 Then %>
<%
'declare your variables
dim connection
dim sSQL1, sConnString

dim thumb
dim itemid
dim itemname
dim Yourprice
dim rrp
dim shipau
dim shipww
dim textfield1
dim textarea1
dim Stock

thumb = request.form("attach1")
Stock = request.Form("Stock")
itemid1 = request.form("itemid")
itemname = request.form("itemname")
Yourprice = request.form("Yourprice")
rrp = request.form("rrp")
shipau = request.form("shipau")
shipww = request.form("shipww")
textfield1 = request.form("textfield")
textarea1 = request.form("textarea")

'declare SQL statement that will query the database



sSQL1="INSERT INTO items (Thumbnail,CategoryID,Product,YourPrice,RRP, ShippingCostAU, ShippingCostWRLD,ProductInfo,ExtraInfo,Closed) VALUES ('"&thumb&"', '"&itemid1&"', '"&itemname&"', '"&Yourprice&"', '"&rrp&"', '"&shipau&"', '"&shipww&"', '"&textfield1&"', '"&textarea1Stock&"', '"&Stock&"')"

sConnString = MM_AIRcart_STRING

'create an ADO connection object
Set connection = Server.CreateObject("ADODB.Connection")


'Open the connection to the database
connection.Open(sConnString)

'execute the SQL
connection.execute(sSQL1)

'close the object and free up resources
Connection.Close
Set Connection = Nothing

response.Redirect("adminadd.asp?insert=1")
%>
<% Else %><% End If %>

this is the code i am using..

the upload/insert form redirects using the post method and goes to adminadd.asp?insert=2 wich is the same page

so this enables the insert statement to work,

thanks so far for the help :)

cheers

baleric

mehere
05-30-2006, 04:10 PM
can i see your code for the page that has your form?

Baleric
05-31-2006, 01:15 AM
<form action="adminadd.asp?insert=2" method="post" enctype="multipart/form-data" name="frmSend">
<div align="left"><span class="style7"><strong>

<%
Dim diagnostics
if Request.ServerVariables("REQUEST_METHOD") <> "POST" then
diagnostics = TestEnvironment()
if diagnostics<>"" then
response.write "<div style=""margin-left:0; margin-top:0; margin-right:0; margin-bottom:0;"">"
response.write diagnostics
response.write "<p>After you correct this problem, reload the page."
response.write "</div>"
else
response.write "<div style=""margin-left:5"">"
OutputForm()
response.write "</div>"
end if
else
response.write "<div style=""margin-left:5"">"
OutputForm()
response.write SaveFiles()
response.write "<br><br></div>"
end if

%>
<br>
Item Image ( 200 x 200 pixels ) <br>
<input name="attach1" type="file" class="style34" size=35>
</strong> <br>
<br>
Filename<br>
<input name="attach2" type="text" id="attach2">
<br>

<br>
Item Category <br>
<select name="itemid" id="itemid">
<option value="<%=(RsModels.Fields.Item("ID").Value)%>"><%=(RsModels.Fields.Item("Types").Value)%></option>
</select>
<br>
<br>
Item Name <br>
<input name="itemname" type="text" class="style34" id="itemname">
</strong></span><span class="style7"><strong><br>
<br>
Your Price<br>
<input name="Yourprice" type="text" id="Yourprice">
</strong></span><span class="style7"><strong><br>
<br>
RRP<br>
<input name="rrp" type="text" id="rrp">
</strong></span><span class="style7"><strong><br>
<br>
Shipping Cost Australia<br>
<input name="shipau" type="text" id="shipau">
</strong></span><span class="style7"><strong><br>
<br>
Shipping Cost World Wide <br>
<input name="shipww" type="text" id="shipww">
</strong></span><span class="style7"><strong> <br>
<br>
</strong></span>
<p>
<label>
<strong>Current Stock</strong><br>
<input type="radio" name="Stock" value="0">
No</label>
<br>
<label>
<input name="Stock" type="radio" value="1" checked>
Yes</label>
<span class="style7"><strong><br><br>
Item Brief Description <br>
<input type="text" name="textfield">
</strong></span><span class="style7"><strong><br>
<br>
Item Indepth Description<br>
<textarea name="textarea" cols="80" rows="15" class="style34"></textarea>
</strong></span><span class="style19"><strong><br>
<br>
</span><span class="style7"><br>

<input name="addbtn" type="submit" id="addbtn" value="Add Item">

<img src="../Images/spacer.gif" alt="Dig" width="20" height="1">

<input name="addbtn2" type="reset" id="addbtn2" value="Reset">
<br>
<br>
<!-- End of additional elements -->
</span></p>
</div>
</form>

thats the form with all my insert fields and upload field...

cheers,

baleric

vipul0827
02-19-2008, 06:13 AM
Hello Baleric,

Hi How R U I Need A help from you can you pls help me

Can You Pls Send Me Your Working Upload And Insert Additional Information Source Code To Me For Doing That I Am Very Thankful To You:)

Cheers In Your Way

Have A Nice Day & Night

Vipul, INDIA