Solved

ASPUpload - updating existing record using form param, PT II

Posted on 2006-07-14
11
350 Views
Last Modified: 2009-12-16
this question is related to this (answered yesterday):
http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21918804.html

i thought i tested it but apparently something fell through the cracks!

i'm not able to update an existing record - so if i have a record who's ContentID is 65 and i try to update the filename in in the db when i do my upload to the server, taint happening-  if there's no filename the filename doesn't get added to the existing record - here's my code:

<!-- AspUpload Code samples: odbc_upload.asp -->
<!-- Invoked by odbc.asp -->
<!-- Copyright (c) 2001 Persits Software, Inc. -->
<!-- http://www.persits.com -->

<HTML>
<BODY>


<%
      Set Upload = Server.CreateObject("Persits.Upload")

      ' Capture files
      Upload.Save "E:\inetpub\wwwroot\smbb\newsite\news\pdfs\"

      ' Obtain file object
      Set File = Upload.Files("THEFILE")

      For Each File in Upload.Files

            datapath="E:\inetpub\wwwroot\smbb\smbb.mdb"
            strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & datapath
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open strConn  
                  
  set rs = Server.CreateObject("ADODB.RecordSet")
     
Dim rsContentID__MMColParam
rsContentID__MMColParam = "ContentID"

SQL = "SELECT * FROM Content WHERE ContentID = " + Replace(rsContentID__MMColParam, "'", "''") + ""
 rs.Open SQL,objConn,1,2

  if rs.eof then
     rs.AddNew
  end if

          rs("filename") = File.ExtractFileName
          rs.Update
          rs.Close
          set rs = nothing
          objConn.Close
          set objConn = nothing

          Response.Write "Your PDF has been successfully uploadedd.  <a href='index.asp'>Click here</a> to return to the admin."
      Next
%>

</BODY>
</HTML>

Thanks!!!


0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 31

Expert Comment

by:alorentz
ID: 17108292
>>if there's no filename the filename doesn't get added to the existing record

What's this mean?  No filename?  Why would you have that?

Also, may want to check your database to see if records are being added...because will do that is EOF.
0
 

Author Comment

by:phillystyle123
ID: 17108404
just rolled out of bed so i'm a tad less articulate than usual

records are being added to the db - i checked. i'm updating existing db records by updating the 'filename' field. basically, my client wants to upload pdfs and add links to those pdfs on the site-  one per record.  the pdf filenames are being added to records that have other fields, title, article, date, etc.

0
 
LVL 31

Expert Comment

by:alorentz
ID: 17108457
OK, so please explain the problem again...as it relates to this code.

Also, always be sure to response.write your variables and SQL...so you know what's actually going on.  Sometimes we assume the code is performing as expected, but the code is not what we expect at all.
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:phillystyle123
ID: 17108500
ok -

i'm passing along the form variable "ContenID"

i need the code to do this:

update 'filename' in db where db.ContentID=formparampassed.ContentID
0
 

Author Comment

by:phillystyle123
ID: 17122282
ugh  still struggling with this - how would i use response.write to display the form variable i'm trying to pass?

something like this?

Response.Write (rsContentID__MMColParam)

0
 

Author Comment

by:phillystyle123
ID: 17122317
ust did this

Response.Write rsContentID__MMColParam

and this is what i got so i'm guessing the form variable isn't being passed or it is but my code thinks the variable is "ContentID":

"Your PDF has been successfully uploadedd. Click here to return to the admin.ContentID"
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17122861
Stop using the stupid DW variables all together....they are annoying.    

contentid=request("contentid")

if contentid ="" then
   response.write "ContentID is empty"
else
  response.write "Content ID: " & contentid
end if


SQL = "SELECT * FROM Content WHERE ContentID = " & contentid
 rs.Open SQL,objConn,1,2

if rs.eof then
     rs.AddNew
  end if

          rs("filename") = File.ExtractFileName

...etc...
0
 

Author Comment

by:phillystyle123
ID: 17124549
thanks alorentz

using your code i'm getting the following error:

Request object error 'ASP 0208 : 80004005'

Cannot use generic Request collection

/newsite/admin/smbbnews/odbc_upload.asp, line 28

Cannot use the generic Request collection after calling BinaryRead.

here's your code built into the existing code:

<!-- AspUpload Code samples: odbc_upload.asp -->
<!-- Invoked by odbc.asp -->
<!-- Copyright (c) 2001 Persits Software, Inc. -->
<!-- http://www.persits.com -->

<HTML>
<BODY>


<%
      Set Upload = Server.CreateObject("Persits.Upload")

      ' Capture files
      Upload.Save "E:\inetpub\wwwroot\smbb\newsite\news\pdfs\"

      ' Obtain file object
      Set File = Upload.Files("THEFILE")

      For Each File in Upload.Files

            datapath="E:\inetpub\wwwroot\smbb\smbb.mdb"
            strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & datapath
            Set objConn = Server.CreateObject("ADODB.Connection")
            objConn.Open strConn  
                  
  set rs = Server.CreateObject("ADODB.RecordSet")
     
contentid=request("contentid")

if contentid ="" then
   response.write "ContentID is empty"
else
  response.write "Content ID: " & contentid
end if


SQL = "SELECT * FROM Content WHERE ContentID = " & contentid
 rs.Open SQL,objConn,1,2

  if rs.eof then
     rs.AddNew
  end if

          rs("filename") = File.ExtractFileName
          rs.Update
          rs.Close
          set rs = nothing
          objConn.Close
          set objConn = nothing

          Response.Write "Your PDF has been successfully uploadedd.  <a href='index.asp'>Click here</a> to return to the admin."
               Response.Write ContentID
      Next
%>

</BODY>
</HTML>

0
 
LVL 31

Accepted Solution

by:
alorentz earned 500 total points
ID: 17124661
Now we are getting somewhere <grin>

Change:

 contentid=request("contentid")

 to

 contentid=Upload.Form("contentid")

When uploading images in binary, you have to use the Upload component as the request object.   otherwise you use the request object.
0
 
LVL 31

Expert Comment

by:alorentz
ID: 17124681
You can also see all that on the code sample page, that yuo've been too:

http://www.aspupload.com/codesample.html 
0
 

Author Comment

by:phillystyle123
ID: 17125654
thanks alorentz - all seems to be working - much appreciated
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help with query 3 41
Adjust an existing ASP Query 45 28
Send form to asp server side 6 37
JQuery & Classic ASP 10 39
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question