0

I have a page where a database lookup is done, and if a value is found some response is sent back to the user and then the database value is deleted.

I'm calling my delete sub after I've checked the variable but it's like this never happened, although i know the sub ran since the value is now gone from the database.

It seems like the page is loading twice and on the second pass the database value has gone and so it shows as if the database value was never found, but it had to have been found in order to have deleted it (as this was a condition for running the delete sub).

I realize this sounds insane but I've been on this for 2 days and have no idea what's going on. I've tried disabling caching from within IIS and also changing my code so that a value is posted to the database instead of deleting a record and I still get the same thing where my server seems to check the future value of the database before calling the routine that changes it.

Has anyone seen similar behavior to this when reading and writing to the same record on a single page?

Code:

referer = Request.ServerVariables ("HTTP_REFERER")
session("testcode") = right(referer,16)

testcode = session("testcode")

set objcommand = server.createObject("adodb.command")
objcommand.activeconnection = strconnect2
objcommand.commandtext="SELECT codeval,stamp,used from code where     codeval like '" & testcode & "'"
objcommand.commandtype = 1
set objrs = objcommand.Execute
set objcommand = nothing 
countvar = 0

While not objrs.EOF

    if not objrs("used") = true then
        foundcode = true
        countvar = countvar+1
    end if


    objrs.MoveNext
wend


if foundcode = true then
    response.write "Found you!"

    set objcomm5 = server.createobject("adodb.command") 
    objcomm5.activeconnection = strconnect2 
    objcomm5.commandtext = "update code set used = true where codeval like '"&     testcode &"' " 
    objcomm5.commandtype = &H0001

    objcomm5.execute
else
    response.write "Can't be found!"
end if
pepoluan
  • 6,132
  • 4
  • 46
  • 76
  • 2
    Please show us the code. – Bob Mar 20 '15 at 23:43
  • 2
    This code is crazy-vulnerable to sql injection attacks. – Joel Coehoorn Mar 21 '15 at 00:07
  • Where is delete function? You are just updating database. So where your values where gone as you checked? – Ali Sheikhpour Mar 21 '15 at 00:13
  • I changed it to just update a value when foundcode=true If you comment out the objcomm5.execute line it will say "found you" but with that line in place i get "can't be found" where the value being compared in the previous code is somehow changed before the update is performed – Moo Goatcluck Mar 21 '15 at 00:19
  • I should also add that there's about a 10-20% chance that this works properly, it's just that mostly it doesn't - Every time i think it's fixed it only works a few times and then goes back to being odd – Moo Goatcluck Mar 21 '15 at 00:34
  • 1
    Is that the end of the page? For debugging this, I would check the value of testcode right after it's pulled from the session, so "response.write testcode". Also, initialize foundcode to false, while not required, just makes it clearer to me. – Bob Mar 21 '15 at 01:09
  • I've done that and testcode is as expected - i just tried putting a response.end right after the objcomm5.execute line and it still set used to true in my db and displayed "can't be found!" – Moo Goatcluck Mar 21 '15 at 01:12
  • make sure you are not using "on error resume next" – Bob Mar 21 '15 at 01:18
  • Thanks Bob, I don't have that specified anywhere in my code though - this isn't a global setting is it? – Moo Goatcluck Mar 21 '15 at 01:23
  • only just saw thing thing about setting foundcode to false - i did try that earlier but i stripped my code down as much as possible before posting here just to keep it shorter - not being a session var i would hope it starts off as not true anyway - thanks again – Moo Goatcluck Mar 21 '15 at 01:28
  • when do you delete session("testcode")? session remains in the memory so if you don't update the session value, the previous value will be executed. – Ali Sheikhpour Mar 21 '15 at 14:53
  • Not sure what the problem is. You say that you never get to see "Found you!" even though there is matching record in database? – Shadow The GPT Wizard Mar 22 '15 at 08:10

0 Answers0