+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Help using function

  1. #1
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Help using function

    Hi All,

    I have a form that when the submit button is clicked, it will insert the form data to sql table and also upload files to server folder and also send an email.

    I have this all in one function....
    first is
    select statment with insert statement
    then
    uploads files if applicable
    then
    sends email

    i'm not sure if i should have all this in one function or if I need more if statements or error handling.

    problem 1 - if i enter form fields that havent been entered but i have the same file name that has already been submitted...i do get a message about the file has already been submitted and it can't be overwritten(this is good)...but it still adds the form fields to the database and sends out an email...how/where can I prevent it from adding since the file name is the same?

    problem 2 - if i enter something that has already been entered, i do get message about it can't be submitted (this is good), but it still allows file upload and send emails....

    It should only send an email when a new form (not been entered) and valid files (not already uploaded).

    Thanks for any direction with this.

  2. #2
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    something on the order of this should work
    Code:
    If file_name exists then
    	error message
    Else
    	upload file
    	select statement
    	if exists
    		delete file
    		error message
    	else
    		insert statement
    		send email
    	end if
    end if
    
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  3. #3
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Thanks for your help Mehere!

    I got the email part fixed now with your help but still having issue with the top part....I think because the part with the error is in the other aspfile.

    Is there a way in javascript to check if filename already exist on server and stop it there? like i do when there is no eq # entered.

  4. #4
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    not that i'm aware of. what i usually do is upload the document/file and add a datetime stamp to the filename, that way, it's hard to have 2 doucments with the same name.
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  5. #5
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    i think i follow...you already helped me with that part where if i try to upload a file with the same name it won't overwrite it. i need to figure out if the form fields are filled out with new data that hasn't been entered but the file field(s) do already exist, don't add to database. I can't get it to stop adding the record.

    i thought maybe adding the file field(s) to the select statement might help but it doesn't totally cause then it stops it even when i do have new form data and a new file. ..lol.

    Okies...I'll keep seeing what I can do here. Thanks for your replies.

  6. #6
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Quote Originally Posted by mehere View Post
    not that i'm aware of. what i usually do is upload the document/file and add a datetime stamp to the filename, that way, it's hard to have 2 doucments with the same name.
    Hi Mehere,

    so you mean, if i upload a file name myform.doc, then you add it to the database and server as myform_Date_time.doc?

    Thanks!

  7. #7
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    i have a function that creates a unique date/time stamp. like so:
    Code:
    function uniqueStamp(strDate)
         Dim strUnique
         strUnique = datepart("m",strDate) & datepart("d",strDate) & datepart("h",strDate) & datepart("n",strDate) & datepart("s",strDate)
         uniqueStamp = strUnique
    end function
    
    then i use this to append to the file name. something like this
    Code:
    thisFile = split(fileName,".")
    strFile = thisFile(0) & "_" & uniqueStamp(now()) & "." & thisFile(1)
    
    however, the file will upload with the name of the file and you'll have to use filesystemobject to copy the file to a new name ... something like this:
    Code:
    Dim fso
    set fso=CreateObject("Scripting.FileSystemObject")
    fso.CopyFile Server.MapPath(fileName), Server.MapPath(strFile)
    
    this is all rough code, but should give you an idea. and you know where to find me if you have an issue.
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  8. #8
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi Mehere,

    I've got it adding the new name with date/time info in it to the database but having problem with the uploaded file...can't get it to rename with the new name.

    here is what i have so far....i put the copyfile line (blue) but doesn't seem to do anything:
    Code:
    for each fileKey in Upload.UploadedFiles.keys
    	thisFile = split(Upload.UploadedFiles(fileKey).FileName,".")
    	strFile1 = strFile1 & thisFile(0) & "_" & uniqueStamp(now()) & "." & thisFile(1) & ","
    next
    
    if FileName <> "" then	
    	strFile1 = left(strFile1,len(strFile1)-1) 'this will remove the trailing comma
    end if
    
    if strFile <> "" then
    	set oFSO = Server.CreateObject("Scripting.FileSystemObject")
    	if oFSO.FileExists(uploadsDirVar & "/" & strFile) then
    		oFSO.MoveFile uploadsDirVar & "\" & strFile, Server.MapPath("/Files") & "\" & strFile
    		oFSO.CopyFile Server.MapPath("/Files") & "\" & strFile, Server.MapPath("/Files") & "\" & strFile1	
    end if
    	set oFSO = nothing
    end if
    
    strSQL = "Select 1 from tblTestTable where Equipment = '" & strEQNumber & "'"
    Set rs = Conn.Execute(strSQL)
    if rs.eof and rs.bof then
    
     if inStr(strFile1,",") > 0 then
         arrFile = split(strFile1,",")
         blnArray = 1
     end if
      if blnArray = 1 then
    
    SQL Insert statements....
    
    Thanks!

  9. #9
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    436
    Rep Power
    7

    try this:
    Code:
    oFSO.MoveFile uploadsDirVar & "\" & strFile, uploadsDirVar & "\" & strFile1
    
    Quote of the Month:
    Leaders: Leaders are like eagles. We don't have either of them here.

    Questions to Ponder:
    Why do banks charge you a "non-sufficient funds fee" on money they already know you don't have?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  10. #10
    Barn Loyal Rebelle will become famous soon enough Rebelle's Avatar
    Join Date
    Mar 2008
    Posts
    868
    Rep Power
    3

    Hi Mehere,

    ok...i was able to now get a value for my strFile that i was missing...so this one holds the original filename and strFile1 holds the new name with date/time info.

    still having an issue though...i still can't get it to change/rename/move my original file to rename to the new file name.

    when i try this, error on line-file not found:
    Code:
    oFSO.MoveFile uploadsDirVar & "\" & strFile, uploadsDirVar & "\" & strFile1
    
    when i do this, error on line-path not found:
    Code:
    oFSO.MoveFile Server.MapPath("/Files") & "\" & strFile, Server.MapPath("/Files") & "\" & strFile1
    
    do i need to check for fileexists first? i tried with this too but nothing.

    Thanks for any suggestions!

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO