Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - UPDATE Sql problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

UPDATE Sql problem

 Post Reply Post Reply
Author
justinp View Drop Down
Newbie
Newbie
Avatar

Joined: 04 February 2003
Location: United Kingdom
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote justinp Quote  Post ReplyReply Direct Link To This Post Topic: UPDATE Sql problem
    Posted: 06 March 2003 at 9:51am

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("&nbsp;&nbsp;<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
%>

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2003 at 11:01am
Originally posted by justinp justinp wrote:


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

why were you expecting different behavior?

Your code:
strSQL = "SELECT itmImage FROM Items WHERE id=" & request.Querystring("id") & ""

Set ladoImage = ladoConn.Execute(strSQL) 'This runs!
'response.write "FIELD: " & Request.form("frmImageHid") & "

"
'response.write "DB ENTRY: " & ladoImage.fields("itmImage") & "

"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If Request.form("frmImageHid") <> ladoImage.fields("itmImage") then 'Happens after the fact


Edited by MorningZ
Contribute to the working anarchy we fondly call the Internet
Back to Top
justinp View Drop Down
Newbie
Newbie
Avatar

Joined: 04 February 2003
Location: United Kingdom
Status: Offline
Points: 15
Post Options Post Options   Thanks (0) Thanks(0)   Quote justinp Quote  Post ReplyReply Direct Link To This Post Posted: 06 March 2003 at 11:08am

That's only a SELECT statement, that is what selects the image filename from the DB in order to use it on the If Request.form("frmImageHid") <> ladoImage.fields("itmImage") then

For some reason the DB seems to be running the UPDATE SQL at the bottom before it gets to SELECT at the top, don't ask me how.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.