can't get this small easy peasy script to wor

Results 1 to 2 of 2

Thread: can't get this small easy peasy script to wor

  1. #1
    Join Date
    Dec 1969

    Default can't get this small easy peasy script to wor

    What I would like to do is, when a user visits a popup page I would like to log this in a counter EXCEPT I dont want to log repeat visits during that "session" i.e. if they reload the page.<BR>So i created a script which would check the IP address if its "" then it logs and if its not then it ends.<BR><BR>What it is doing is logign all visits:(<BR><BR>If varIP = "" Then<BR>&#039; here is where I put something in the variable varIP<BR>varIP = Request.ServerVariables("REMOTE_HOST")<BR>&#039; what I want to do...<BR>SQLCounterIncrease = "SELECT InfoID, InfoCounter FROM tblInfo WHERE (((tblInfo.InfoID)= " & varInfoID &"));"<BR>Set RSCounterIncrease = Server.CreateObject("ADODB.Recordset")<BR>RSCounte rIncrease.Open SQLCounterIncrease, CN, adOpenDynamic, adLockPessimistic, adCmdText<BR>RSCounterIncrease.Fields("InfoCounter ").Value = RSCounterIncrease.Fields("infoCounter").Value + 1<BR>RSCounterIncrease.Update<BR>RSCounterIncrease .Close<BR>Set RSCounterIncrease = nothing<BR>End If<BR>&#039; varIP is here to show that it now holds a value<BR>varIP = Request.ServerVariables("REMOTE_HOST")<BR>%&#062; <BR><BR>any suggestions?!

  2. #2
    Join Date
    Dec 1969

    Default Variables don't survive end of page...

    You are setting the variable varIP *IN THIS PAGE*.<BR><BR>But when this page is done, that variable is WIPED FROM MEMORY!<BR><BR>So every time you hit this code in a new page, varIP *will* be simply ""!<BR><BR>You need to learn about SESSION VARIABLES. (Which aren&#039;t really variables, but never mind about that for now...)<BR><BR>And let me fix that horribly expensive way you are bumping the counter in the DB while we&#039;re at it!<BR><BR><BR>Try this:<BR><BR>&#060;%<BR>...<BR>varIP = Session("TheHost")<BR>If varIP = "" Then<BR>&nbsp; &nbsp; varIP = Request.ServerVariables("REMOTE_HOST")<BR>&nbsp; &nbsp; SQLCounterIncrease = "UPDATE tblInfo SET InfoCounter = InfoCounter + 1 " _<BR>&nbsp; &nbsp; &nbsp; &nbsp; & " WHERE InfoID = " & varInfoID <BR>&nbsp; &nbsp; CN.Execute( SQLCounterIncrease )<BR>&nbsp; &nbsp; Session("TheHost") = varIP<BR>End If<BR>...<BR>%&#062;<BR><BR>You don&#039;t show where the varInfoID is coming from. I will assume you have taken care of it?<BR><BR>

Posting Permissions

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