Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

code not working why?

Posted on 2001-07-07
6
Medium Priority
?
284 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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 informatio…
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/…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

783 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