Solved

code not working why?

Posted on 2001-07-07
6
225 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 33

Expert Comment

by:hongjun
Comment Utility
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
Comment Utility
Short..Simple..Sweet. Thanks.
0
 
LVL 2

Author Comment

by:cybermoonlight
Comment Utility
thanks everyone
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now