Solved

code not working why?

Posted on 2001-07-07
6
270 Views
Last Modified: 2012-05-04
hey there,, i have a slight prob..my code ain't working.
it says that the operation can't be performed cuz the object is closed? huh
Any help much appreciated
tjhanks

here is the code

<%Option Explicit
Response.Expires = -1

dim objConn, objRS, strSQL, strConn
dim strUsername, strPassword, strIP, strPrepay
dim blAlreadyLoggedIn

strConn = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=/DB/CCDB.mdb"
Set objConn = Server.CreateObject("ADODB.Connection")
strIP = Request.ServerVariables("REMOTE_ADDR")

Private Function CheckSessionClearing()
     
     strSQL = "Select * from tblSession where IP='" & strIP & "' AND Payed = NO;"
     Set objRS = objConn.Execute (strSQL, strConn)
     If objRS.EOF then CheckSessionClearing = True
     set objRS = Nothing
     
End Function

Private Sub UpdateSession()

     strSQL="INSERT INTO tblSession (IP, Username, StartTime) VALUES ('" & strIP &"', '" & strUsername &"', '" & now() & "');"
     objConn.Execute strSQL, strConn
     
End Sub

Private Function CheckUser()

     strSQL = "Select Username,MinutesLeft From tblMembers Where Username = '" & strUsername & "' AND Password= '" & strPassword & "';"
     Set objRS = objConn.Execute (strSQL, strConn)
     If Not objRS.EOF then
          strPrepay = objRS("MinutesLeft")
          if strPrepay = "" or strPrepay = "1" then strPrepay = 0
          CheckUser = True
     End If
     Set objRs = Nothing
     
End Function
%>

<HTML>
<BODY>

<%

If CheckSessionClearing = True then
     If Request.Querystring("Username") = "" then
          strUsername = Request.Form("txtLogin")
          strPassword = Request.Form("txtPassword")
     else
          strUsername = "Cyberguest"
          strPassword = "Cyberguest"
     end if
     If CheckUser = True then
          UpdateSession
          Response.Write("STATUS=OK*USERNAME=" & strUsername & "*PREPAY=" & strPrepay & "*START=" & now() & "*")
     Else
          Response.Write "The username or password you entered is incorrect.<BR><A href=login.htm>Try Again</a>"
     End if
Else
     Response.write "Sorry but an existing session has not yet been cleared. Please contact a member of staff"
End If

ObjConn.Close
Set objConn = Nothing
%>
</BODY>
</HTML>
0
Comment
Question by:cybermoonlight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 5

Accepted Solution

by:
dgorin earned 100 total points
ID: 6261552
I don't see where you open your connection.

You need objConn.Open <connection string> somewhere in your code.
0
 
LVL 2

Author Comment

by:cybermoonlight
ID: 6261567
oh poo, i thought that .execute would automatically open the conn..thanks
i'll just make sure..then give u the points
0
 
LVL 10

Expert Comment

by:Dxpert
ID: 6261628
Here's the correct code:
=======================================================

<%Option Explicit
Response.Expires = -1

dim objConn, objRS, strSQL, strConn
dim strUsername, strPassword, strIP, strPrepay
dim blAlreadyLoggedIn

'open connection
strConn = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=/DB/CCDB.mdb"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open strConn

'get ip address
strIP = Request.ServerVariables("REMOTE_ADDR")


Private Function CheckSessionClearing()
   
    strSQL = "Select * from tblSession where IP='" & strIP & "' AND Payed = NO;"
    Set objRS = objConn.Execute (strSQL)
    If objRS.EOF then CheckSessionClearing = True
    set objRS = Nothing
   
End Function

Private Sub UpdateSession()

    strSQL="INSERT INTO tblSession (IP, Username, StartTime) VALUES ('" & strIP &"', '" & strUsername
&"', '" & now() & "');"
    objConn.Execute (strSQL)
   
End Sub

Private Function CheckUser()

    strSQL = "Select Username,MinutesLeft From tblMembers Where Username = '" & strUsername & "' AND
Password= '" & strPassword & "';"
    Set objRS = objConn.Execute (strSQL)
    If Not objRS.EOF then
         strPrepay = objRS("MinutesLeft")
         if strPrepay = "" or strPrepay = "1" then strPrepay = 0
         CheckUser = True
    End If
    Set objRs = Nothing
   
End Function
%>


======================================================
You were missing a couple of "()" too.

=:o)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 33

Expert Comment

by:hongjun
ID: 6261880
Try this. I added replace function for strings in sql statements to prevent syntax error if the value contains single quotes.

<%Option Explicit
Response.Expires = -1

dim objConn, objRS, strSQL, strConn
dim strUsername, strPassword, strIP, strPrepay
dim blAlreadyLoggedIn

strConn = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=/DB/CCDB.mdb"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConn
strIP = Request.ServerVariables("REMOTE_ADDR")

Private Function CheckSessionClearing()
   
    strSQL = "Select * from tblSession where IP='" & replace(strIP, "'", "''") & "' AND Payed = NO;"
    Set objRS = objConn.Execute(strSQL)
    If objRS.EOF then CheckSessionClearing = True
    set objRS = Nothing
   
End Function

Private Sub UpdateSession()

    strSQL="INSERT INTO tblSession (IP, Username, StartTime) VALUES ('" & replace(strIP, "'", "''") & "', '" & replace(strUsername, "'", "''") & "', '" & now() & "');"
    objConn.Execute strSQL
   
End Sub

Private Function CheckUser()

    strSQL = "Select Username,MinutesLeft From tblMembers Where Username = '" & replace(strUsername, "'", "''") & "' AND Password = '" & replace(strPassword, "'", "''") & "';"
    Set objRS = objConn.Execute(strConn)
    If Not objRS.EOF then
         strPrepay = objRS("MinutesLeft")
         if strPrepay = "" or strPrepay = "1" then strPrepay = 0
         CheckUser = True
    End If
    Set objRs = Nothing
   
End Function
%>

<HTML>
<BODY>

<%

If CheckSessionClearing = True then
    If Request.Querystring("Username") = "" then
         strUsername = Request.Form("txtLogin")
         strPassword = Request.Form("txtPassword")
    else
         strUsername = "Cyberguest"
         strPassword = "Cyberguest"
    end if
    If CheckUser = True then
         UpdateSession
         Response.Write("STATUS=OK*USERNAME=" & strUsername & "*PREPAY=" & strPrepay & "*START=" & now() & "*")
    Else
         Response.Write "The username or password you entered is incorrect.<BR><A href=login.htm>Try Again</a>"
    End if
Else
    Response.write "Sorry but an existing session has not yet been cleared. Please contact a member of staff"
End If

ObjConn.Close
Set objConn = Nothing
%>
</BODY>
</HTML>

hongjun
0
 
LVL 2

Author Comment

by:cybermoonlight
ID: 6263101
Short..Simple..Sweet. Thanks.
0
 
LVL 2

Author Comment

by:cybermoonlight
ID: 6263102
thanks everyone
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question