 |
| Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 25th, 2013, 01:08 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problem with upload file to server and add values in Database
Hello and Merry Christmas to all!
I`m trying to make a web page in order to upload some files to server and add some values in my db.
I downloaded a script from http://www.freeaspupload.net/freeaspupload/download.asp and it works great!
At the end of the page I`m adding my code and then an error occurs.
the error is
Error Type:
Runtime error Microsoft VBScript (0x800A01F4)
the variable is not set: 'Upload'
/g/1upload/uploadTester.asp, line 194
(i had to translate the error message from greek to english, so I hope I made no errors in translation)
The code I`m adding in the uploadTester.asp is the following
Code:
<%
Dim adoCon 'Holds the Database Connection Object
Dim rsAddComments 'Holds the recordset for the new record to be added to the database
Dim strSQL 'Holds the SQL query for the database
Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("guestbook.mdb")
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT files.* FROM files;"
rsAddComments.CursorType = 2
rsAddComments.LockType = 3
rsAddComments.Open strSQL, adoCon
rsAddComments.AddNew
rsAddComments.Fields("name") = Upload.Form("enter_a_number") <--this is the line 194
rsAddComments.Fields("file") = Upload.Form("attach1")
rsAddComments.Update
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
%>
thank you in advance!
|
|

December 26th, 2013, 12:48 AM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Its been a while since I've coded in Classic ASP.
I don't think you need to use the 'Upload' object to add the variable to the database. I think you can just set the variable outside of that Upload object and add it to the database.
A trick I used to use for classic is to see if you can just write your variable to the page to see if you're getting anything there.
Response.Write(Upload.Form("enter_a_number"))
Response.End
|
|

December 27th, 2013, 10:37 AM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
on the script I found that "response.write" works fine. But when I try to insert this value in my db then the problem comes up. It can`t find that Upload. object (the one that I use on the response.write command)
Have you checked the code I use?? I can`t find what the problem.
|
|

December 27th, 2013, 01:19 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Yes. I looked at your code.
OK. You can try hard coding a value and see if that inserts into the database.
And you can try assigning Your Upload.Form("enter_a_number") to a variable and then use that variable on your insert.
Dim EnterANumber
Enter_A_Number = Upload.Form("enter_a_number")
rsAddComments.Fields("name") = Enter_A_Number
You need to see if your insert works first. Then see if you're getting your variable assigned correctly and then you may have trouble with the data type.
What is the actual error that you're getting?
rsAddComments.Fields("name") = "TestValue" <--this is the line 194 rsAddComments.Fields("file") = "TestValue2"
|
|

December 28th, 2013, 06:49 PM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
you rule mate!!! my problem is solved with your help! :D
Now I have some more things to deal with... I want to make that form with only two "file fields" and the file names shall be saved in my db. Also I want to make it work even if there are no files to be uploaded.
I hope that I`ll make it through! :)
If not I`m going to bother you once more! :P
Last edited by Varg_88; December 28th, 2013 at 06:52 PM..
|
|

December 28th, 2013, 07:59 PM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I`m almost done. The only thing is that I have 2 "file fields" in my db and I can`t save both filenames.
The problem I have is that I have to dim a variable in the "for each" procedure. So for both filenames there is the same filename saved in two different fields in the db.
I don`t know how to make that work without using the "for each" procedure. Here is the code I`m using
Code:
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) "
Dim bloodtests
bloodtests = Upload.UploadedFiles(fileKey).FileName
next
else
SaveFiles = "No file selected for upload or the file name specified in the upload form does not correspond to a valid file in the system."
end if
I`m thinking that I could Dim bloodtests, bloodtests1 before the "for each" procedure but I don`t know how I could write a different value in "bloodtests" and "bloodtests1".
|
|

December 29th, 2013, 01:10 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
OK. Good.
Yes. You can do basically any kind of loop.
Like I said its been a while since I've worked with Classic so my syntax may be a little off.
So it looks like the code you posted creates an array [UBound(ks)]. If your upload function is always going to contain two values then you may be able to access both those values with something like:
bloodtests = Upload.UploadedFiles(0).FileName
bloodtests1 = Upload.UploadedFiles(1).FileName
or it might be
bloodtests = Upload.UploadedFiles(1).FileName
bloodtests1 = Upload.UploadedFiles(2).FileName
Play around with that and see if you can get the values you want.
You can also do:
Response.Write(ks)
Response.End
to see what that value is. Since you are uploading two files at a time (I think) then that number should be 2.
|
|

December 29th, 2013, 06:36 PM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
dear rstelma you were more than helpful with your suggestions!!! :D
They key to my solution was to use
response.write filekey in the loop.
So the results was:
bloodtests1 = Upload.UploadedFiles("attach1").FileName
bloodtests2 = Upload.UploadedFiles("attach2").FileName
and now my problem is done!!! :D Thank you very much!!!
Now I`m thinking to make it a little more complex.
The script right now saves the files in a folder. After some months this folder shall be full of images! I`m just thinking to add to the script a few lines in order to create a subfolder (with the customers name) in order to have that image folder a little bit more organized.
I hope that I shall be able to do that... although I`m a real newbie! :)
|
|

December 29th, 2013, 09:34 PM
|
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
|
|
Great! You're welcome. Glad I could help.
I like the idea of subfolders. Good idea.
|
|

December 30th, 2013, 06:13 PM
|
|
Friend of Wrox
|
|
Join Date: May 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I was feeling almost done with this but something new came up... Sounds like Muprhy`s Law...
Now that I use:
Code:
Dim xray, bloodtests
xray = Upload.UploadedFiles("attach1").FileName
bloodtests = Upload.UploadedFiles("attach2").FileName
when I want to upload only one file and not two... or even when I don`t want to upload any file I get an error:
--- error ---
object required 'Upload.UploadedFiles(...)'
---
I tried to make use "if - then - else" using IsNull(Upload.UploadedFiles("attach1").FileName) or
Upload.UploadedFiles("attach1").FileName="" but there were no results.
Also I`m trying to make that thing with the subfolders I mention but it`s a little difficult for me to set the value of the subfolder. Here is the code I use:
Code:
<%
function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey, newdir, pathname, filesys
Set Upload = New FreeASPUpload
pathname = Upload.Form("name")
newdir = "C:\guestbook_example\UploadedFiles\" & patname & ""
set filesys=CreateObject("Scripting.FileSystemObject")
if not filesys.FolderExists(newdir) then
filesys.CreateFolder (newdir)
end if
response.write newdir
response.write "<br>"
response.write "this is the path name:" & pathname & ""
response.write "<br>"
Upload.Save(newdir)
' 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 = "No file selected for upload"
end if
%>
I tried to insert a value in "pathname"(e.g 123) and the subfolder 123 was created. But the Upload.Form("name") returns no value. Right after the code I pasted I start to insert the Upload.Form("...") values in my db and everything is working great. I can`t find out why pathname="" ??
Last edited by Varg_88; December 30th, 2013 at 06:15 PM..
|
|
 |