Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "Help using function" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old August 19th, 2008, 03:12 PM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Question 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.
Reply With Quote
Sponsored Links
  #2  
Old August 19th, 2008, 03:18 PM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

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:
Regret: It hurts to admit when you make mistakes - but when they're big enough, the pain only lasts a second.

Questions to Ponder:
Could it be that all those trick-or-treaters wearing sheets aren’t going as ghosts but as mattresses?

iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
copyright © 2008 sbenj69
Reply With Quote
  #3  
Old August 20th, 2008, 10:26 AM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old August 20th, 2008, 11:28 AM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

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.
Reply With Quote
  #5  
Old August 20th, 2008, 11:39 AM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old October 8th, 2008, 11:27 AM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

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!
Reply With Quote
  #7  
Old October 8th, 2008, 12:01 PM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

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.
Reply With Quote
  #8  
Old October 10th, 2008, 12:28 PM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

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!
Reply With Quote
  #9  
Old October 10th, 2008, 12:39 PM
mehere's Avatar
Super Sarcasm Mistress


 
Join Date: Mar 2008
Location: Wide Awake In Dreamland
Posts: 143
Thanks: 10
Thanked 27 Times in 25 Posts
Rep Power: 1
mehere will become famous soon enough

Awards Showcase
Microsoft SQL Server Classic ASP 
Total Awards: 2

Default

try this:
Code:
oFSO.MoveFile uploadsDirVar & "\" & strFile, uploadsDirVar & "\" & strFile1

Comments on this post
Rebelle agrees: Thanked Post
Reply With Quote
The Following User Says Thank You to mehere For This Useful Post:
Rebelle (October 13th, 2008)
  #10  
Old October 13th, 2008, 10:21 AM
Rebelle's Avatar
V.I.P/Donor


 
Join Date: Mar 2008
Posts: 254
Thanks: 48
Thanked 1 Time in 1 Post
Rep Power: 1
Rebelle is on a distinguished road
Default

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 With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 06:16 PM.



Content Relevant URLs by vBSEO 3.2.0