Hi.
I was wondering if anyone can help me. I'm using the code below to update records in a DB. The data comes from a form that the user submits. When editing, if a user uploads a new image via the form, the code checks the DB, if the image uploaded is different to the filename in the DB, then the image file referenced in the DB is deleted and the new filename is updated in the DB.
The problem I'm getting is that it seems to be updating the DB entry before it even gets to this line:
If Request.form("frmImageHid") <> ladoImage.fields("itmImage") then
The other part of the code is used to rename the image depending on other information used in the form. I've tested the code to see how far it gets before it changes the DB.
I used these lines for testing:
'response.write "FIELD: " & Request.form("frmImageHid") & "<br><br>"
'response.write "DB ENTRY: " & ladoImage.fields("itmImage") & "<br><br>"
When the lines above are run the DB has already updated, this is before I've run the UPDATE SQL at the bottom.
I'm lost as to why it does this, has anyone any ideas by looking at my code??
Many Thanks
JP
<%
Case "Update"
strSQL = "SELECT itmImage FROM Items WHERE id=" & request.Querystring("id") & ""
Set ladoImage = ladoConn.Execute(strSQL)
'response.write "FIELD: " & Request.form("frmImageHid") & "<br><br>"
'response.write "DB ENTRY: " & ladoImage.fields("itmImage") & "<br><br>"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Request.form("frmImageHid") <> ladoImage.fields("itmImage") then
'Set path to image
strPath=server.MapPath("\images\uploaded\") & "\"
strFileName = strPath & ladoImage.fields("itmImage")
Set strFinalStep = objFSO.GetFile(strFileName)
'Delete Image
strFinalStep.Delete
strItmName=Request.form("frmItmName")
'Request Image name
strOldFileName= strPath & Request.form("frmImageHid")
strPartName=replace(strItmName, " ", "_") & ".gif"
strNewFileName= strPath & strPartName
'Response.write "NOT EQUAL TO<br><br>"
'Response.write "Old File Name:" & strOldFileName & "<br><br>"
'Response.write "New File Name:" & strNewFileName & "<br><br>"
If objFso.fileExists(strNewFileName)=false Then
objFso.MoveFile strOldFileName,strNewFileName
Else
Response.write(" <br><br>File already Exists")
End If
strDateTime = FormatDateTime(now(),1) & " " & FormatDateTime(now(),3)
strInsertSQL = "UPDATE Items SET itmImage='" & strPartName & "', itmName='" & Request.form("frmItmName") & "', itmCat='" & Request.form("itmCat") & "', itmDate='" & strDateTime & "' WHERE id=" & request.Querystring("id") & ""
Else
'Set path to image
strPath=server.MapPath("\images\uploaded\") & "\"
strItmName=Request.form("frmItmName")
'Request Image name
strOldFileName= strPath & Request.form("frmImageHid")
strPartName=replace(strItmName, " ", "_") & ".gif"
strNewFileName= strPath & strPartName
'Response.write "EQUAL TO<br><br>"
'Response.write "Old File Name:" & strOldFileName & "<br><br>"
'Response.write "New File Name:" & strNewFileName & "<br><br>"
If objFso.fileExists(strNewFileName)=false Then
objFso.MoveFile strOldFileName,strNewFileName
End If
strDateTime = FormatDateTime(now(),1) & " " & FormatDateTime(now(),3)
strInsertSQL = "UPDATE Items SET itmImage='" & strPartName & "', itmName='" & Request.form("frmItmName") & "', itmCat='" & Request.form("itmCat") & "', itmDate='" & strDateTime & "' WHERE id=" & request.Querystring("id") & ""
End If
ladoConn.Execute(strInsertSQL)
ladoConn.close
%>