« Previous Next »

Thread: ASP: Urgent Help needed for uploading files to database

Last post 12-02-2007 9:57 PM by thomad. 1 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (2 items)

Sort Posts:

  • 11-01-2007, 2:46 PM

    • rbhathal
    • Not Ranked
    • Joined on 10-06-2006, 7:50 PM
    • Posts 2

    ASP: Urgent Help needed for uploading files to database

    I have 2 forms, submit.asp(It's action is form.asp) and form.asp and the backend db is Access. when I use enctype="multipart/form-data" in submit.asp the contents of the textboxes never get stored in database and I get the error: (The <b>Suggestion Summary and the Suggestion Type</b> fields are a required fields.  Please click the back button at the top of the browser and re-submit the form) which is created in Form.asp

     Other error I get is that  Cannot call Request.Form collection after using BinaryRead .I browsed thru net and if I use Recordset how can I modify the line, product_process=request.form("slproduct") so that it does not use Request.Form. Please note this value is read from Submit.asp

    the codes for both files  are below:

     Form.asp

     <% ' Insert.asp %>
    <!--#include file="Loader.asp"-->
    <%
      Response.Buffer = True

     'If UCase(Request.ServerVariables("REQUEST_METHOD")) <> "POST" Then 'Request method must be "POST"

      ' load object
      Dim load
        Set load = new Loader

        ' calling initialize method
        load.initialize

      ' File binary data
      Dim fileData
        fileData = load.getFileData("file")
      ' File name
      Dim fileName
        fileName = LCase(load.getFileName("file"))
      ' File path
      Dim filePath
        filePath = load.getFilePath("file")
      ' File path complete
      Dim filePathComplete
        filePathComplete = load.getFilePathComplete("file")
      ' File size
      Dim fileSize
        fileSize = load.getFileSize("file")
      ' File size translated
      Dim fileSizeTranslated
        fileSizeTranslated = load.getFileSizeTranslated("file")
      ' Content Type
      Dim contentType
        contentType = load.getContentType("file")
      ' No. of Form elements
      Dim countElements
        countElements = load.Count
      ' Value of text input field "fname"
      Dim fnameInput
        fnameInput = load.getValue("fname")
      ' Value of text input field "lname"
      Dim lnameInput
        lnameInput = load.getValue("lname")
      ' Value of text input field "profession"
      Dim profession
        profession = load.getValue("profession")

      ' destroying load object
      Set load = Nothing
      'End If
    %>
    <html>
    <head>
    <!-- #BeginEditable "doctitle" -->
    <TITLE>NBCO Improvement Suggestions</TITLE>
    <!-- #EndEditable -->
    <meta http-equiv="Content-Type" content="text/html;">
    <meta name="Description" content="Ideatech">
    <meta name="keywords" content="IdeaTech">
    <script language="JavaScript">
    <!--
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    // -->

    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
    //-->
    </script>
    <%

    Username = LCase(Trim(Request.ServerVariables("REMOTE_USER")))
    pos = InStrRev(Username, "\")
    UserName = Mid(Username, pos + 1)

    message=""

    fname=REPLACE(rtrim(ltrim(request.form("txtfname"))),"'","''")
    lname=REPLACE(rtrim(ltrim(request.form("txtlname"))),"'","''")

    product_process=request.form("slproduct")

    summary=REPLACE(rtrim(ltrim(request.form("txtsummary"))),"'","''")
    description=REPLACE(rtrim(ltrim(request.form("tadescription"))),"'","''")
    benefits=REPLACE(rtrim(ltrim(request.form("tabenefits"))),"'","''")
    other=REPLACE(rtrim(ltrim(request.form("taother"))),"'","''")
    Recommendations=REPLACE(rtrim(ltrim(request.form("taRecommendations"))),"'","''")

    FileName =Request.form("Filebrowse")

    if len(summary) > 0 and len(product_process) > 0then

     set conntemp=server.createobject("adodb.connection")

         ' DSNless connection to Access Database
     DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
     DSNtemp=dsntemp & "DBQ=" & server.mappath("\acr\database\acr.mdb")
     conntemp.Open DSNtemp


     sql="Insert into idea (date_submitted,username,fname,lname,summary,benefits, details,other, activate_status,status, Recommendations)"

     if len(product_process) > 0 then
      'sql = sql & " values (#" & now() & "#,'" & UserName & "','" & fname & "','" & lname & "','" & summary & "','" & benefits & "','" & description & "','" & other & "',FALSE," & product_process & ")"
      sql = sql & " values (#" & now() & "#,'" & UserName & "','" & fname & "','" & lname & "','" & summary & "','" & benefits & "','" & description & "','" & other & "',FALSE," & product_process & ",'" & Recommendations & "', '" & FileName & "')"
     else
       'sql = sql & " values (#" & now() & "#,'" & UserName & "','" & fname & "','" & lname & "','" & summary & "','" & benefits & "','" & description & "','" & other & "',FALSE,40)"
       sql = sql & " values (#" & now() & "#,'" & UserName & "','" & fname & "','" & lname & "','" & summary & "','" & benefits & "','" & description & "','" & other & "',FALSE,40, '" & Recommendations & "', '" & FileName & "')"
     end if
    'response.write sql
     conntemp.execute(SQL)

     conntemp.close
     set conntemp=nothing

     

     

    dim Mailer
    set Mailer=Server.CreateObject("CDONTS.NewMail")
    Mailer.From="Intranet@abc.com"
    Mailer.To="acris@abc.com"
    Mailer.Subject ="Suggestion Submitted"

    crlf= chr(10) & chr(13)
    txtmsg= txtmsg & "Name: " & lname & ", " & fname + crlf
    txtmsg= txtmsg & "Login: " & Username &crlf
    txtmsg=txtmsg & "Summary: " & summary & crlf
    txtmsg=txtmsg & "Descrition: " & description  & crlf
    txtmsg=txtmsg & "Benefits: " & benefits & crlf
    txtmsg=txtmsg & "Other: " & other & crlf
    txtmsg=txtmsg & "Date Submitted: " & now() & crlf
    txtmsg=txtmsg & "Recommendations: " & Recommendations & crlf

    Mailer.Body=txtmsg

    Mailer.Send

     


    message = "Summary: " & summary & crlf
    message = message & "product_process: " & product_process & crlf


     message= message & "Thank you for submitting your suggestions/concerns. Your recommendations will be reviewed and a response will be communicated to you as soon as possible.<br><br>- Improvement Suggestions Coordinator<br>(On behalf of the NBC Improvement Suggestions Committee)"

    else

    message = "Summary: " & summary & crlf
    message = message & "product_process: " & product_process & crlf

      message= message &  "The <b>Suggestion Summary and the Suggestion Type</b> fields are a required fields.  Please click the back button at the top of the browser and re-submit the form."
    end if


    %>



    </body>
    </html>


    <tr>
           <td>File :</td><td>
          <input type="file" name="filebrowse" size="40"></td></tr>
     <td> </td>
       </tr>


     

    Submit.asp

     

    <html>
    <head>
    <!-- #BeginEditable "doctitle" -->
    <TITLE>NBC Improvement Suggestions / Quality or Safety Concerns</TITLE>
    <!-- #EndEditable -->
    <meta http-equiv="Content-Type" content="text/html;">
    <meta name="Description" content="Ideatech">
    <meta name="keywords" content="IdeaTech">
    <script language="JavaScript">
    <!--
    <!--
    function MM_reloadPage(init) {  //reloads the window if Nav4 resized
      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
    }
    MM_reloadPage(true);
    // -->

    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }

     


    '}
    //-->
    </script>
    <%
    cnt1=0
    cnt2=0
    'cnt3=0
    'seloptionproduct=""
    seloptionprocess=""
    set conntemp=server.createobject("adodb.connection")
       ' DSNless connection to Access Database
        DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)}; "
        DSNtemp=dsntemp & "DBQ=" & server.mappath("\acr\database\acr.mdb")
         conntemp.Open DSNtemp
         ' DSNless connection to Access Database

       'sql="SELECT * from status where active=TRUE and type='Product' order by status_id"


       'set rstemp=conntemp.execute(SQL)

       'seloptionproduct2 = "document.form1.slproduct.options.length=0; "
       'do until rstemp.EOF

       'seloptionproduct= seloptionproduct & "<option value='" & rstemp("status_id") & "'>" & rstemp("status_description") & "</option>"
       'seloptionproduct2= seloptionproduct2 & " document.form1.slproduct[" & cnt1 & "]=new Option('" & rstemp("status_description") & "', '" & rstemp("status_id") & "', false);"
       'cnt1=cnt1+1

       'rstemp.moveNext
             'Loop
       'rstemp.close
       'set rstemp=nothing

       'sql="SELECT * from status where active=TRUE and type='Process' order by status_id"
       sql="SELECT * from status where active=TRUE and type='IS-Improvement Suggestion' order by status_id"


       set rstemp=conntemp.execute(SQL)

       seloptionprocess2 = "document.form1.slproduct.options.length=0; "
       do until rstemp.EOF

          seloptionprocess= seloptionprocess & "<option value='" & rstemp("status_id") & "'>" & rstemp("status_description") & "</option>"
       seloptionprocess2= seloptionprocess2 & " document.form1.slproduct[" & cnt1 & "]=new Option('" & rstemp("status_description") & "', '" & rstemp("status_id") & "', false);"
       cnt1=cnt1+1
       rstemp.moveNext
             Loop
       rstemp.close
       set rstemp=nothing

       'sql="SELECT * from status where active=TRUE and type='Safety' order by status_id"
       sql="SELECT * from status where active=TRUE and type='QSC-Quality or Safety Concern' order by status_id"


       set rstemp=conntemp.execute(SQL)

       seloptionSafety2 = "document.form1.slproduct.options.length=0; "
       do until rstemp.EOF

       seloptionSafety= seloptionSafety & "<option value='" & rstemp("status_id") & "'>" & rstemp("status_description") & "</option>"
       seloptionSafety2= seloptionSafety2 & " document.form1.slproduct[" & cnt2 & "]=new Option('" & rstemp("status_description") & "', '" & rstemp("status_id") & "', false);"
       cnt2=cnt2+1
       rstemp.moveNext
             Loop

        rstemp.close
        set rstemp=nothing

        conntemp.close
        set conntemp=nothing
    %>
    <script language="JavaScript">

    function menu_switch(tk) {

     switch (tk){

        case 0:
           <%=seloptionprocess2%>
           break;
        case 1:
           <%=seloptionSafety2%>
           break;
     }


    }
    //-->
    </script>


    <link rel="stylesheet" href="/acr/inc/acr.css" type="text/css">
    </head>
    <body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#ffffff" onLoad="MM_preloadImages('/acr/images/home_roll.gif','/acr/images/submit_roll.gif','/acr/images/sp_roll.gif','/acr/images/contact_roll.gif','/acr/images/links_roll.gif','/acr/images/view_roll.gif','/acr/images/infonet_roll.gif','/acr/images/puzzle_roll.gif')">
    <BR>
    <META content="MSHTML 6.00.2715.400" name=GENERATOR>

    <TABLE cellSpacing=0 cellPadding=0 width=764 align=center border=0 ID="Table1">
      <tr>
        <td valign="top" width="1"  rowspan="5" bgcolor="#669999"><IMG  src="/acr/Images/line.jpg" width=1></td>
        <td colSpan="2" height="60" valign="top" background="/acr/Images/line.jpg"><IMG src="/acr/images/toptemplate.png"  width=762 border=0 height="60"></td>
        <td width="1" rowspan="5" valign="top" bgcolor="#669999" align="left"><IMG height="100%"  src="/acr/Images/line.jpg" width=1></TD>
      </tr>
      <tr height="18">
        <td colspan=2 height="30">
          <TABLE cellSpacing=0 cellPadding=0 width=762 border=0 ID="Table2">
                  </table>
        </td>
      </tr>
      <tr>
        <td colspan=2 bgcolor="#669999" height="2"><IMG height=2
          src="/acr/Images/line.jpg"
      width=762></td>
      </tr>
      <tr>
        <td height="395" width="130" valign="top">
         <TABLE cellSpacing=0 cellPadding=0 width=130 border=0 ID="Table3">
            <TR>
              <TD width=130 valign="middle"   align="center">
               
              </TD>
            </TR>
            <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
              <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
            <TR>
                       </TR>
            <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
            <TR>
              <TD valign="middle" align="center"><a href="/scripts/acr/submit.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image24','','/acr/images/submit_roll.gif',1)"><img name="Image24" border="0" src="/acr/images/submit.gif" width="130" height="38"></a></TD>
            </TR>
            <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
            <TR>
              <TD valign="middle" align="center" ><a href="/scripts/acr/view.asp" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image15','','/acr/images/view_rolls',1)"><img name="Image15" border="0" src="/acr/images/view.gif" width="130" height="38"></a></TD>
            </TR>

            <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
            <TR>
              <TD valign="middle" align="center"  ><a href="mailto:abc@abc.com?subject=Suggestion%20Feedback" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image18','','/acr/images/contact_roll.gif',1)"><img name="Image18" border="0" src="/acr/images/contact.gif" width="130" height="38"></a></TD>
            </TR>
            <TR>
              <TD valign="top"><img src="/acr/images/line.jpg" width="100%" height="1"></TD>
            </TR>
            <tr>
              <td></td>
            </tr>
          </TABLE>
        </td>
        <td width=632 valign="top" rowspan="3" >
          <TABLE cellSpacing=0 cellPadding=0 width=632 border=0 height=415 ID="Table4">
            <tr>
              <td rowspan="3" width="5" bgcolor="#669999"><IMG height="100%" src="/acr/Images/line.jpg" width=1></td>
              <td align="center" class=title colspan="2" height=34 >&nbsp;<!-- #BeginEditable "Title" --><b>NBC Improvement Suggestions / Quality or Safety Concerns</b><!-- #EndEditable --></td>
              <td width="1"></td>
            </tr>
            <tr>
              <td colspan="2" height=1 bgcolor="#669999"><IMG height=1 src="/acr/Images/line.jpg" width=630></td>
              <td></td>
            </tr>
            <tr>
              <td width=10 height="380" valign="top">&nbsp;</td>
              <td width=620 valign=top class="glance"><br>
                <!-- #BeginEditable "Body" -->

     <form name="form1" method="post"  action="form.asp" ID="Form1">
     'enctype="multipart/form-data"

                <input type="hidden" name="hlogin" value=<%=UserName %> ID="Hidden1">
         <table width="100%" border="0" ID="Table5">
           <tr>
             <td>First Name:</td>
             <td>
               <input type="text" name="txtfname" size="30" maxlength="100" ID="Text1">
             </td>
           </tr>
           <tr>
             <td valign="top">Last Name:</td>
             <td>
               <input type="text" name="txtlname" size="30" maxlength="100" ID="Text2">
             </td>
           </tr>
           <tr>
                 <td>

                 Suggestion Type<br></td><td><Select name="sltype" onchange="menu_switch(document.form1.sltype.selectedIndex)" ID="Select1"><option>IS- Improvement Suggestion</option><option>QSC - Quality or Safety concern</option></select></td>
                 </tr>
                 <tr><td></td>
                 <td><Select name="slproduct" ID="Select2"><%=seloptionprocess%></select></td>
                 </td>
           </tr>
           <tr>
             <td valign="top">Suggestion Summary:</td>
             <td>
               <input type="text" name="txtsummary" size="55" maxlength="255" ID="Text3">
             </td>
           </tr>
           <tr>
             <td valign="top">Detailed Description:</td>
             <td>
               <textarea name="taDescription" cols="50" rows="5" ID="Textarea1"></textarea>
             </td>
           </tr>
           <tr>
             <td valign="top">Benefit/Concern:</td>
             <td>
               <textarea name="taBenefits" cols="50" rows="5" ID="Textarea2"></textarea>
             </td>
           </tr>
           <tr>
             <td valign="top">Recommendations:</td>
             <td>
               <textarea name="taRecommendations" cols="50" rows="5" ID="Textarea3"></textarea>
             </td>
           </tr>
           <tr>
             <td valign="top">Additional Information/References:</td>
             <td>
               <textarea name="taOther" cols="50" rows="5" ID="Textarea4"></textarea>
             </td>
           </tr>

            <tr>
                <td>File :</td><td>
          <input type="file" name="filebrowse" size="40"></td></tr>

           <tr>
             <td colspan="2">
               <div align="center">
                 <input type="submit" name="Submit" value="Submit" ID="Submit1">
                 <input type="reset" name="Submit2" value="Clear" ID="Reset1">
               </div>
             </td>
           </tr>
         </table>
       </form>
                <!-- #EndEditable --></td>
              <td></td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td height="18" align="center" valign="middle">
          <ADDRESS STYLE="font-size: 11px; font-style: italic; font-family: Arial; line-height: 12px">Created Dec 2003</address></td>

      </tr>

      <tr>
        <td height="2"></td>
        <td></td>
        <td></TD>
      </tr>
      <tr>
        <td height="2"></td>
        <td colspan=2 valign="top" bgcolor="#669999"><IMG height=2
          src="/acr/Images/line.jpg"
      width="762"></td>
        <td></TD>
      </tr>
    </table>

    <P align=center>&nbsp;</P>
    </body>
    </html>

  • 12-02-2007, 9:57 PM In reply to

    • thomad
    • Top 25 Contributor
    • Joined on 08-20-2002, 3:28 PM
    • Redmond
    • Posts 503

    Re: ASP: Urgent Help needed for uploading files to database

    Rbhathal,

    Most of the people in this forum have busy lifes. I bet nobody is going to read through your code or even copy it and trying it out because it is way too much.

    The best way to get help on your problem is to reduce the code to the absolute minimum.

    Hope this helps

    Thomas Deml
    Program Manager
    Internet Information Services
    Microsoft Corp.
Page 1 of 1 (2 items)
Microsoft Communities