|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello everyone,
This is my first post, unfortunately its a cry for help! I've been having troubles with a registration page im trying to get to work, i keep getting the error: - An error occured. 3704 : Operation is not allowed when the object is closed Here is the code for the page and an include file: inc-dbconnection.asp <% dim objConn Set objConn = Server.CreateObject("ADODB.Connection") objConn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\inetpub\wwwroot\tester\db\testdb.mdb" %> here is the code on the registration page: <% Option Explicit Dim strError, strSQL 'see if the form has been submitted If Request.Form("action")="register" Then 'the form has been submitted '// validate the form 'check if a username has been entered If Request.Form("username") = "" Then _ strError = strError & "- Please enter a username<br>" & vbNewLine 'check if a password has been entered If Request.Form("password") = "" Then _ strError = strError & "- Please enter a password<br>" & vbNewLine 'check if the passwords are the same... but don't display it if the password field is blank. If Request.Form("password") <> Request.Form("password_confirm") _ And Request.Form("password") <> "" Then _ strError = strError & "- Your passwords do not match<br>" & vbNewLine '// check if an error has occured If strError = "" Then 'continue 'include database connection code %> <!--#include file="inc-dbconnection.asp"--> <% On Error Resume Next '// create the SQL strSQL = "INSERT INTO members ([username],[password]) VALUES " & _ "('" & fixQuotes(Request.Form("username")) & "','" & _ fixQuotes(Request.Form("password")) & "')" '// run the SQL objConn.Execute strSQL '// check for an error '// ATTENTION: this should be changed depending on the database provider If Err.Number = -2147467259 Then strError = "- That username is already in use. Please choose another<br>" & vbNewLine ElseIf Err.Number <> 0 Then strError = "- An error occured. " & Err.Number & " : " & _ Err.Description & "<br>" & vbNewLine Else 'record created... redirect Response.Redirect "login.asp?msg=" & Server.URLEncode("Thank you for registering") Response.End End If 'restore standard error handling On Error Goto 0 End If If strError <> "" Then 'output the error message 'add extra HTML... strError = "<p><font color=""#FF0000"">The following errors occured:" & _ "</font><br>" & vbNewLine & strError End If End If Function fixQuotes(strData) fixQuotes = Replace(strData,"'","''") End Function %> <html> <head> <title>Registration Page</title> </head> <body> <h1>Member Registration</h1> <p>Please fill out the following form to register as a member, and gain access to our members area.</p> <%=strError%> <form action="register.asp" method="POST"> <input type="hidden" name="action" value="register"> <table border="0"> <tr> <td><b>Username</b></td> <td><input type="text" maxlength=20 name="username" value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td> </tr> <tr> <td><b>Password</b></td> <td><input type="password" maxlength=20 name="password" value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td> </tr> <tr> <td><b>Password Confirm</b></td> <td><input type="password" maxlength=20 name="password_confirm" value="<%=Server.HTMLEncode(Request.Form("password_confirm"))%>"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Complete Registration"></td> </tr> </table> </form> Thank you in advance, Pogo </body> </html> |
|
#2
|
|||
|
|||
|
Don't forget to open you connection first before executing you sql statement:
Code:
objConn.open |
|
#3
|
|||
|
|||
|
Quote:
Cheers for that it did the trick then i got another error to do with the database (just needed to change permissions), but i fixed that now, I can now register and login however when i test entering a wrong password or username, press the button and an error is displayed (my validation on the form) and then type the correct one in it throws an error on the 25 line of the login page: Login.asp <% Option Explicit Dim strError, strSQL, objRS 'see if the form has been submitted If Request.Form("action")="login" Then 'the form has been submitted '// validate the form 'check if a username has been entered If Request.Form("username") = "" Then _ strError = strError & "- Please enter a username<br>" & vbNewLine 'check if a password has been entered If Request.Form("password") = "" Then _ strError = strError & "- Please enter a password<br>" & vbNewLine '// check if an error has occured If strError = "" Then 'continue 'include database connection code %> <!--#include file="inc-dbconnection.asp"--> <% objConn.Open <-------------------------------------------------------- 25th line '// create the SQL strSQL = "SELECT id,password FROM members WHERE username='" & _ fixQuotes(Request.Form("username")) & "'" '// run the SQL Set objRS = objConn.Execute (strSQL) '// see if there are any records returned If objRS.EOF Then 'no username found strError = "- Invalid username or password<br>" & vbNewLine Else 'check password If objRS("password")=Request.Form("password") Then 'username/password valid 'save session data Session("loggedin") = True Session("userid") = objRS("id") 'redirect to members area Response.Redirect ("default.asp") Response.End Else 'invalid password strError = "- Invalid username or password<br>" & vbNewLine End If End If End If If strError <> "" Then 'output the error message 'add extra HTML... strError = "<p><font color=""#FF0000"">The following errors occured:" & _ "</font><br>" & vbNewLine & strError End If 'display message in URL.. (ie thank you for registering) If Request.QueryString("msg") <> "" And strError = "" Then strError = "<p>" & Request.QueryString("msg") & "</p>" End If End If Function fixQuotes(strData) fixQuotes = Replace(strData,"'","''") End Function're-set session data (ie log out)Session("loggedin")="" Session("userid")="" %> <html> <head> <title>Members Area Login</title> </head> <body> <h1>Members Area Login</h1> <p>Please enter your username and password to access the Members Area.</p> <%=strError%> <form action="login.asp" method="POST"> <input type="hidden" name="action" value="login"> <table border="0"> <tr> <td><b>Username</b></td> <td><input type="text" maxlength=20 name="username" value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td> </tr> <tr> <td><b>Password</b></td> <td><input type="password" maxlength=20 name="password" value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td> </tr> <tr> <td> </td> <td><input type="submit" value="Login"></td> </tr> </table> </form> </body> </html> Cheers |
|
#4
|
|||
|
|||
|
Sorry about that. I think your connection is still open when you are trying to open it the second time.
Close the connection after you use it: Code:
'// run the SQL Set objRS = objConn.Execute (strSQL) objConn.close then it will not be already open next time around |
|
#5
|
|||
|
|||
|
Quote:
Hey, Thanks for your help, i put in what you said but unfortunatly got an error on line 33: If objRS.EOF Then What im doing is just testing the form to see if i can put false information, and then when ive tested the fields i put in the write username and password but it throws an error! Cheers |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Operation is not allowed when the object is closed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|