Solved

code not working why?

Posted on 2001-07-07
6
265 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select case on click 3 31
Asp in server side with Mssql Server 7 4 43
Filktering Alphabetically 8 46
ms sql string field to asp variable as number 5 32
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…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

752 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