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
Solved

code not working why?

Posted on 2001-07-07
6
255 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
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Can not run ASP pages Windows 10 Edge browser. 5 100
UTC (timezone) without using an API 16 50
Auto Submit on dropdown box 3 79
Html form and modal / img src -problem 3 28
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

789 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