title: How to Insert Record and Upload file using the FreeASPUpload Script
body: <p>I want to Insert record and upload file at the same time, right now im using <a href="http://www.freeaspupload.net/" rel="nofollow">FreeASPUpload</a> Script. When i submit the form it returns this error </p>
  
  <pre><code>Cannot use the generic Request collection after calling BinaryRead
  </code></pre>
  
  <p><strong>Here is the Full Source Code of my page</strong></p>
  
  <pre><code>&lt;% 
  option explicit 
  Response.Expires = -1
  Server.ScriptTimeout = 600
  Session.CodePage  = 65001
  %&gt;
  &lt;!-- #include file="UploadClass.asp" --&gt;
  &lt;%
  
    Dim uploadsDirVar
    uploadsDirVar = server.MapPath("Files_Uploaded") 
  
  function OutputForm()
  %&gt;
  &lt;form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="form.asp" onSubmit="return onSubmitForm();"&gt;
  &lt;input type="hidden" name="ApplicationForm" value="Insert" /&gt;
  Name: &lt;input type="text" name="name_insert" value="" size="30" /&gt;
      &lt;B&gt;File names:&lt;/B&gt;&lt;br&gt;
      File 1: &lt;input name="attach1" type="file" size=35&gt;&lt;br&gt;
      &lt;br&gt; 
      &lt;input style="margin-top:4" type="submit" value="Submit"&gt;
      &lt;/form&gt;
  &lt;%
  end function
  
  function TestEnvironment()
      Dim fso, fileName, testFile, streamTest
      TestEnvironment = ""
      Set fso = Server.CreateObject("Scripting.FileSystemObject")
      if not fso.FolderExists(uploadsDirVar) then
          TestEnvironment = "&lt;B&gt;Folder " &amp; uploadsDirVar &amp; " does not exist.&lt;/B&gt;&lt;br&gt;The value of your uploadsDirVar is incorrect. Open uploadTester.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 &amp; "\test.txt"
      on error resume next
      Set testFile = fso.CreateTextFile(fileName, true)
      If Err.Number&lt;&gt;0 then
          TestEnvironment = "&lt;B&gt;Folder " &amp; uploadsDirVar &amp; " does not have write permissions.&lt;/B&gt;&lt;br&gt;The value of your uploadsDirVar is incorrect. Open uploadTester.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&lt;&gt;0 then
          TestEnvironment = "&lt;B&gt;Folder " &amp; uploadsDirVar &amp; " does not have delete permissions&lt;/B&gt;, although it does have write permissions.&lt;br&gt;Change the permissions for IUSR_&lt;I&gt;computername&lt;/I&gt; on this folder."
          exit function
      end if
      Err.Clear
      Set streamTest = Server.CreateObject("ADODB.Stream")
      If Err.Number&lt;&gt;0 then
          TestEnvironment = "&lt;B&gt;The ADODB object &lt;I&gt;Stream&lt;/I&gt; is not available in your server.&lt;/B&gt;&lt;br&gt;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&lt;&gt;0 then Exit function
  
      SaveFiles = ""
      ks = Upload.UploadedFiles.keys
      if (UBound(ks) &lt;&gt; -1) then
          SaveFiles = "&lt;B&gt;Files uploaded:&lt;/B&gt; "
          for each fileKey in Upload.UploadedFiles.keys
              SaveFiles = SaveFiles &amp; Upload.UploadedFiles(fileKey).FileName &amp; " (" &amp; Upload.UploadedFiles(fileKey).Length &amp; "B) "
          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
      SaveFiles = SaveFiles &amp; "&lt;br&gt;Enter a number = " &amp; Upload.Form("enter_a_number") &amp; "&lt;br&gt;"
      SaveFiles = SaveFiles &amp; "Checkbox values = " &amp; Upload.Form("checkbox_values") &amp; "&lt;br&gt;"
      SaveFiles = SaveFiles &amp; "List values = " &amp; Upload.Form("list_values") &amp; "&lt;br&gt;"
      SaveFiles = SaveFiles &amp; "Text area = " &amp; Upload.Form("t_area") &amp; "&lt;br&gt;"
  end function
  %&gt;
  &lt;HTML&gt;
  &lt;HEAD&gt;
  &lt;TITLE&gt;Test Free ASP Upload 2.0&lt;/TITLE&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;style&gt;
  BODY {background-color: white;font-family:arial; font-size:12}
  &lt;/style&gt;
  &lt;script&gt;
  function onSubmitForm() {
      var formDOMObj = document.frmSend;
      if (formDOMObj.attach1.value == "")
          alert("Please press the Browse button and pick a file.")
      else
          return true;
      return false;
  }
  &lt;/script&gt;
  
  &lt;/HEAD&gt;
  
  &lt;BODY&gt;
  
  &lt;br&gt;&lt;br&gt;
  &lt;div style="border-bottom: #A91905 2px solid;font-size:16"&gt;Upload files to your server&lt;/div&gt;
  &lt;%
  Dim diagnostics
  if Request.ServerVariables("REQUEST_METHOD") &lt;&gt; "POST" then
      diagnostics = TestEnvironment()
      if diagnostics&lt;&gt;"" then
          response.write "&lt;div style=""margin-left:20; margin-top:30; margin-right:30; margin-bottom:30;""&gt;"
          response.write diagnostics
          response.write "&lt;p&gt;After you correct this problem, reload the page."
          response.write "&lt;/div&gt;"
      else
          response.write "&lt;div style=""margin-left:150""&gt;"
          OutputForm()
          response.write "&lt;/div&gt;"
      end if
  else
      response.write "&lt;div style=""margin-left:150""&gt;"
      OutputForm()
      response.write SaveFiles()
      response.write "&lt;br&gt;&lt;br&gt;&lt;/div&gt;"
  end if
  
  %&gt;
  
  &lt;/BODY&gt;
  &lt;/HTML&gt;
  &lt;!-- #include file="ADOVBS.inc" --&gt;
  &lt;%
  
  '=======================================================================================
  ' CONNECT DATABASE
  '=======================================================================================
  Dim objConn, objRs
  Set objConn = CreateObject("ADODB.Connection")
  Set objRs = CreateObject("ADODB.Recordset")
  objConn.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&amp; server.MapPath("db/Job_database.mdb") &amp;";Mode=ReadWrite|Share Deny None;Persist Security Info=False"
  
  If Request("ApplicationForm") = "Insert" Then
  Set InsCom=Server.CreateObject("ADODB.Command")
  InsCom.ActiveConnection=objConn
  
  InsName = Trim(request("name_insert"))
  InsName = replace(InsName,"'","''")
  
  InsCom.CommandText = "Insert into applications(aname)Values(?)"
  InsCom.Parameters.Append InsCom.CreateParameter("@name_insert", adVarChar, adParamInput, 255, InsName)
  
  InsCom.Execute
  
  End If
  %&gt;
  </code></pre>
  
  <p>I have been searching for this problem, but couldn't make it work. although what i found is that i have to use the <code>Form Collection</code> provided by FreeASPUpload. therefore i change </p>
  
  <pre><code>If Request("ApplicationForm") = "Insert" Then
  </code></pre>
  
  <p>to this</p>
  
  <pre><code>If Upload.Form("ApplicationForm") = "Insert" Then
  </code></pre>
  
  <p>But it also returns an error, that says: <strong>Variable is undefined: 'Upload'</strong></p>
  
  <p>If i change the Request method, it only Uploads the file not inserts the record</p>
  
  <pre><code>If Request.QueryString("ApplicationForm") = "Insert" Then
  </code></pre>
  
  <p>What i understands is that my insert query is in wrong place or so...</p>
  
  <p>Please help me solve this problem.. thanks</p>