473,408 Members | 2,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

ASP Upload File and Add database fields

I think this is probably some minor oversight on my end but I'm just missing it.

I have a multipart/form-data form in a ASP page. Inside the form I have traditional text fields and a upload field for uploading images to a server.

The intent is to store the image name (not the image itself) along with corresponding data in a SQL Server database.

The problem I'm currently having is that the upload is working correctly but it is not writing any data into the database. The page does not report an error it just simply does not write. It's like the page the form submits to isn't getting the data from the form because nothing is in the fields when I do a
Expand|Select|Wrap|Line Numbers
  1.  response.write 
.

Here's the code. Any help is greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1.       Title = Request("Title")
  2.       ShortTitle = Request("ShortTitle")
  3.       SubmittedBy = Request("SubmittedBy")
  4.       StoryDate = Request("StoryDate")
  5.       StoryEndDate = Request("StoryEndDate")
  6.       Story = Request("Story")
  7.  
  8.       'Response.Write story
  9.       if instr(1,Story,"<P>") = 1 then
  10.             Story = mid(Story,4,len(Story))
  11.       end if
  12.  
  13.       Set StrConnection = Server.CreateObject("ADODB.Connection")
  14.       Set StrRecordSet = Server.CreateObject("ADODB.Recordset")
  15.       StrConnection.Open "Provider=MSDASQL;Driver={SQL Server};SERVER=FF-CORPSQL;DATABASE=testannouncements;uid=intranet;pwd=reltd;"
  16.       StrSql = "SELECT * FROM announcements;"
  17.  
  18.       StrRecordSet.Open StrSql, StrConnection,1,2
  19.         if Title <> "" then
  20.         with StrRecordSet
  21.               .AddNew 
  22.                    Title= Replace(Title, "'", "^")
  23.                    StrRecordSet("Title")=Title
  24.                       ShortTitle= Replace(ShortTitle, "'", "^")
  25.                    StrRecordSet("ShortTitle")=ShortTitle
  26.  
  27.                    SubmittedBy= Replace(SubmittedBy, "'", "^")
  28.                    StrRecordSet("SubmittedBy")=SubmittedBy
  29.                    StoryDate= Replace(StoryDate, "'", "^")
  30.                    StrRecordSet("StoryDate")=StoryDate
  31.                    'StoryEndDate= Replace(StoryEndDate, "'", "^")
  32.                    if StoryEndDate <> "" then
  33.                         StrRecordSet("StoryEndDate")=StoryEndDate
  34.                    end if
  35.                    Story= Replace(Story, "'", "^")
  36.                    StrRecordSet("Department") = Request("Department")
  37.                    StrRecordSet("Story")=Story
  38.                    'if filename = "" then
  39.                     '    If Request("StoryPic") <> "None" then
  40.                     '        StrRecordSet("picture")=Request("StoryPic")
  41.                     '    end if
  42.                    'else
  43.                     '    StrRecordSet("picture")=filename
  44.                    'end if    
  45.                  .Update 
  46.         end with
  47.     end if
  48.     set strrecordset = nothing
  49.     StrConnection.Close 
  50.     set StrConnection = nothing
  51.     %>
  52.     <!--#include file="upload.asp" -->
  53.     <%
  54.     Dim Uploader, File, ErrMsg
  55.     Set Uploader = New FileUploader
  56.     ' This starts the upload process
  57.     Uploader.Upload()
  58.  
  59.     '******************************************
  60.     ' Use [FileUploader object].Form to access 
  61.     ' additional form variables submitted with
  62.     ' the file upload(s). (used below)
  63.     '******************************************
  64.  
  65.     ' Check if any files were uploaded
  66.     If Uploader.Files.Count = 0 Then
  67.     '    Response.Redirect("add_news.asp")
  68.     Else
  69.         ' Loop through the uploaded files
  70.         For Each File In Uploader.Files.Items
  71.  
  72.             ' Check where the user wants to save the file
  73.             If Uploader.Form("saveto") = "disk" Then
  74.                 ' Save the file
  75.                 File.SaveToDisk strDISKLOCATION 
  76.             End If
  77.             Dim filename
  78.             filename = File.FileName '& "<br>"
  79.         Next
  80.     End If
  81.  
Nov 19 '07 #1
9 2771
jhardman
3,406 Expert 2GB
First do a basic troubleshoot to see if the form data made it:
Expand|Select|Wrap|Line Numbers
  1. for each x in request.form
  2.    response.write x & ": " & request.form(x) & "<br>" & vbNewline
  3. next
Try it and tell me what you get.

Jared
Nov 21 '07 #2
Sorry for the delay in my response.

I added the code and nothing is written
Nov 27 '07 #3
jhardman
3,406 Expert 2GB
Sorry for the delay in my response.

I added the code and nothing is written
Then the form data is not being sent. post the code for your form.

Jared
Nov 27 '07 #4
Expand|Select|Wrap|Line Numbers
  1.        <form name="LayoutRegion1FORM" enctype="multipart/form-data" action="/admin/test/html/announcements/addnewsresult.asp" method="POST">
  2.         <table border="0" cellspacing="0" cellpadding="0">
  3.          <tr valign="top" align="left">
  4.           <td height="24"></td>
  5.          </tr>
  6.          <tr valign="top" align="left">
  7.           <td width="557">
  8.            <table id="Table8" border="0" cellspacing="2" cellpadding="2" width="100%" style="height: 276;">
  9.             <tr style="height: 26px;">
  10.              <td width="126">
  11.               <p style="text-align: right;"><b><span style="font-size: x-small;">Title:</span></b></p>
  12.              </td>
  13.              <td width="417">
  14.               <p><input id="FormsEditField6" type="text" name="Title" style="white-space:pre" value="" size="42" maxlength="500"></p>
  15.              </td>
  16.             </tr>
  17.             <tr style="height: 26px;">
  18.              <td>
  19.               <p style="text-align: right;"><b><span style="font-size: x-small;">Short Title:</span></b></p>
  20.              </td>
  21.              <td>
  22.               <p><input id="FormsEditField9" type="text" name="ShortTitle" style="white-space:pre" value="" size="20" maxlength="20"></p>
  23.              </td>
  24.             </tr>
  25.             <tr style="height: 26px;">
  26.              <td>
  27.               <p style="text-align: right;"><b><span style="font-size: x-small;">Date:</span></b></p>
  28.              </td>
  29.              <td>
  30.               <p><input id="FormsEditField7" type="text" name="StoryDate" style="white-space:pre" value="" size="23" maxlength="50"></p>
  31.              </td>
  32.             </tr>
  33.             <tr style="height: 26px;">
  34.              <td>
  35.               <p style="text-align: right;"><b><span style="font-size: x-small;">Submitted By:</span></b></p>
  36.              </td>
  37.              <td>
  38.               <p><input id="txtID" type="text" name="submittedby" style="white-space: pre;" value="<%= strhold %>" size="23" maxlength="23"></p>
  39.              </td>
  40.             </tr>
  41.             <tr style="height: 26px;">
  42.              <td>
  43.               <p style="text-align: right;"><b><span style="font-size: x-small;">Department:</span></b></p>
  44.              </td>
  45.              <td>
  46.               <p><input id="Department" type="text" name="Department" style="white-space:pre" value="" size="23" maxlength="50"></p>
  47.              </td>
  48.             </tr>
  49.             <tr style="height: 146px;">
  50.              <td>
  51.               <p>&nbsp;</p>
  52.              </td>
  53.              <td>
  54.               <p>&nbsp;</p>
  55.               <p><input type="button" name="button1" value="Bold" id="button1" ONCLICK="insertString('<B>')">&nbsp;<input type="button" name="button2" value="Stop Bold" id="button2" ONCLICK="insertString('</B>')"><br><input type="button" name="button1" value="Italics" id="FormsButton5" ONCLICK="insertString('<I>')">&nbsp;<input type="button" name="button2" value="Stop Italics" id="FormsButton6" ONCLICK="insertString('</I>')"><br><input type="button" name="button1" value="Underline" id="FormsButton7" ONCLICK="insertString('<U>')">&nbsp;<input type="button" name="button2" value="Stop Underline" id="FormsButton8" ONCLICK="insertString('</U>')"><br><input type="button" name="button4" value="New Paragraph" id="FormsButton9" ONCLICK="insertString('<P>')"></p>
  56.              </td>
  57.             </tr>
  58.             <tr style="height: 246px;">
  59.              <td>
  60.               <p style="text-align: right;"><b><span style="font-size: x-small;">Story:</span></b></p>
  61.              </td>
  62.              <td>
  63.               <p><textarea id="Story" name="Story" style="white-space: pre;" rows="15" cols="50" onclick=setCursorPos() onchange=setCursorPos()></textarea></p>
  64.              </td>
  65.             </tr>
  66.            </table>
  67.           </td>
  68.          </tr>
  69.         </table>
  70.         <table border="0" cellspacing="0" cellpadding="0" width="464">
  71.          <tr valign="top" align="left">
  72.           <td width="134" height="25"><img src="../../assets/images/autogen/clearpixel.gif" width="134" height="1" border="0" alt=""></td>
  73.           <td></td>
  74.          </tr>
  75.          <tr valign="top" align="left">
  76.           <td height="22"></td>
  77.           <td width="330"><input type="file" name="FILE1" size="50"><input TYPE="radio" NAME="saveto" value="disk" checked></td>
  78.          </tr>
  79.         </table>
  80.         <table border="0" cellspacing="0" cellpadding="0">
  81.          <tr valign="top" align="left">
  82.           <td width="20" height="10"><img src="../../assets/images/autogen/clearpixel.gif" width="20" height="1" border="0" alt=""></td>
  83.           <td></td>
  84.          </tr>
  85.          <tr valign="top" align="left">
  86.           <td></td>
  87.           <td width="553">
  88.            <table id="Table9" border="1" cellspacing="1" cellpadding="1" width="100%" style="height: 86;">
  89.             <tr align="center" style="height: 100px;">
  90.              <td width="105">
  91.               <p style="text-align: center;">-None-</p>
  92.              </td>
  93.              <td width="105">
  94.               <p style="text-align: center;"><img id="Picture4" height="100" width="81" src="../../assets/images/1.gif" vspace="0" hspace="0" align="TOP" border="0" alt="1" title="1"></p>
  95.              </td>
  96.              <td width="105">
  97.               <p style="text-align: center;"><img id="Picture5" height="100" width="81" src="../../assets/images/2.gif" vspace="0" hspace="0" align="TOP" border="0" alt="2" title="2"></p>
  98.              </td>
  99.              <td width="105">
  100.               <p style="text-align: center;"><img id="Picture6" height="100" width="81" src="../../assets/images/3.gif" vspace="0" hspace="0" align="TOP" border="0" alt="3" title="3"></p>
  101.              </td>
  102.              <td width="105">
  103.               <p style="text-align: center;"><img id="Picture7" height="100" width="81" src="../../assets/images/4.gif" vspace="0" hspace="0" align="TOP" border="0" alt="4" title="4"></p>
  104.              </td>
  105.             </tr>
  106.             <tr align="center" style="height: 19px;">
  107.              <td>
  108.               <p><input id="FormsRadioButton1" type="radio" CHECKED name="StoryPic" value="None">&nbsp;</p>
  109.              </td>
  110.              <td>
  111.               <p><input id="FormsRadioButton2" type="radio" name="StoryPic" value="image1.gif">&nbsp;</p>
  112.              </td>
  113.              <td>
  114.               <p><input id="FormsRadioButton3" type="radio" name="StoryPic" value="image2.gif">&nbsp;</p>
  115.              </td>
  116.              <td>
  117.               <p><input id="FormsRadioButton4" type="radio" name="StoryPic" value="image3.gif">&nbsp;</p>
  118.              </td>
  119.              <td>
  120.               <p><input id="FormsRadioButton5" type="radio" name="StoryPic" value="image4.gif">&nbsp;</p>
  121.              </td>
  122.             </tr>
  123.            </table>
  124.           </td>
  125.          </tr>
  126.         </table>
  127.         <table border="0" cellspacing="0" cellpadding="0" width="381">
  128.          <tr valign="top" align="left">
  129.           <td width="197" height="19"><img src="../../assets/images/autogen/clearpixel.gif" width="197" height="1" border="0" alt=""></td>
  130.           <td></td>
  131.          </tr>
  132.          <tr valign="top" align="left">
  133.           <td height="24"></td>
  134.           <td width="184"><input type="submit" name="Submit" value="Add Announcement" id="FormsButton11"></td>
  135.          </tr>
  136.         </table>
  137.        </form>
  138.  
Nov 27 '07 #5
Nicodemas
164 Expert 100+
I see that you are making requests to the from the Request object. When sending binary data through a form, and making a request to any Request object other than Request.Querystring, you cannot access the binary data.

The Upload API you have provides you with a method to get the binary data. Use that to retrieve all your form values instead of the Request object.

Instantiate your API first, then do your form value retrievals.
Nov 28 '07 #6
jhardman
3,406 Expert 2GB
I see that you are making requests to the from the Request object. When sending binary data through a form, and making a request to any Request object other than Request.Querystring, you cannot access the binary data.

The Upload API you have provides you with a method to get the binary data. Use that to retrieve all your form values instead of the Request object.

Instantiate your API first, then do your form value retrievals.
I'm not sure that's the problem, he says he is trying to save the file name in the db and that is accessible from the request object...
Nov 28 '07 #7
jhardman
3,406 Expert 2GB
Sorry for the delay in my response.

I added the code and nothing is written
you added my code to addnewsresult.asp? This is just supposed to write the data to the screen, not to the db...
Nov 28 '07 #8
Yes, I added it the result page and actually just removed all the other code to see if it was being passed.

Nothing was displayed.

I actually customized the code I found at this site. And got it working. http://www.codeproject.com/asp/aspupl.asp

I would've rather gotten my own working though.
Nov 29 '07 #9
jhardman
3,406 Expert 2GB
Yes, I added it the result page and actually just removed all the other code to see if it was being passed.

Nothing was displayed.

I actually customized the code I found at this site. And got it working. http://www.codeproject.com/asp/aspupl.asp

I would've rather gotten my own working though.
Glad you got it working regardless, That is what those sites are for, after all.

Jared
Nov 29 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Stephane | last post by:
Hello, I need to allow an end user to upload video files on a server and in the same time to put the file name and a few infos in a database. It must be very simple for the end user, and...
5
by: Thomas Brooks | last post by:
Hi there.... I have an ASP routine that I'm writing which updates an Access database with a user name, the file name, etc. all done through parameter processing and SQL functions. I do not...
4
by: NohaKhalifa | last post by:
Dear All; I'm developing a web site and i need to make adminisration for this site it's a site for Real Estates . But I don't need the administration to be online .. I want them to fill data...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
4
by: kev | last post by:
Hi folks, I have created a database to store information on equipments. During the first level of registration, there is a form that i need the user to fill up details on the equipment testing....
3
by: Stephan | last post by:
Hi all, I am new to access and I face the following "issue": I would like to create a database, to which users can upload files (=pdf, doc, xls...). The files shall be stored locally on a...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.