Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsOtherProgramming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 5th, 2005, 07:13 AM
pogo_juice pogo_juice is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 30 pogo_juice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 30 sec
Reputation Power: 4
Question Operation is not allowed when the object is closed

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>

Reply With Quote
  #2  
Old April 5th, 2005, 08:28 AM
pmcnamee pmcnamee is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 28 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 22 m 25 sec
Reputation Power: 0
Don't forget to open you connection first before executing you sql statement:

Code:
objConn.open
Comments on this post
nofriends agrees!

Reply With Quote
  #3  
Old April 5th, 2005, 09:35 AM
pogo_juice pogo_juice is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 30 pogo_juice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 30 sec
Reputation Power: 4
Quote:
Originally Posted by pmcnamee
Don't forget to open you connection first before executing you sql statement:

Code:
objConn.open


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

Reply With Quote
  #4  
Old April 5th, 2005, 10:14 AM
pmcnamee pmcnamee is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 28 pmcnamee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 22 m 25 sec
Reputation Power: 0
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

Reply With Quote
  #5  
Old April 5th, 2005, 10:52 AM
pogo_juice pogo_juice is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 30 pogo_juice User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 22 m 30 sec
Reputation Power: 4
Quote:
Originally Posted by pmcnamee
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


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

Reply With Quote
Reply

Viewing: ASP Free ForumsOtherProgramming Help > Operation is not allowed when the object is closed


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway