Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Try Your Hand at this One!

Status
Not open for further replies.

Jesus4u

Programmer
Feb 15, 2001
110
US
I have this code here where I am registering users into my website. Everything works fine meaning I can write into the DB but when I test to see if the passwords are the same I get this error:

Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/ReclaimAmerica.org/test.asp, line 98

Now I flagged line 98 with ++++++++
---------------------------------------------------------
Any help would be appreciated!

<!-- #INCLUDE FILE=&quot;data.asp&quot; -->
<% Response.Buffer = true %>
<%
'-- Check if Submit button pushed, if not ignore the entire script
If Request.Form(&quot;btnAdd&quot;) = &quot;Submit&quot; Then

'-- Make sure all boxes have data entered into them
If Request.Form(&quot;name&quot;) <> &quot;&quot; OR Request.Form(&quot;password&quot;) <> &quot;&quot; OR _
Request.Form(&quot;password2&quot;) <> &quot;&quot; OR _
Request.Form(&quot;email&quot;) <> &quot;&quot; OR _
Request.Form(&quot;userID&quot;) <> &quot;&quot; Then

'-- Make sure the passwords match
If Request.Form(&quot;password&quot;) = Request.Form(&quot;password2&quot;) Then

'-- Declare your variables
Dim DataConnection, cmdDC, RecordSet, SQL, strError
Dim strUserName, strPassword, strEmail, strUserID

'-- Get data from the form fields
strUserName = Request.Form(&quot;name&quot;)
strPassword = Request.Form(&quot;password&quot;)
strEmail = Request.Form(&quot;email&quot;)
strUserID = Request.Form(&quot;userID&quot;)

'-- Create object and open database
Set DataConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
DataConnection.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)};&quot; &amp; _
&quot;DBQ=&quot; &amp; DatabasePath &amp; &quot;;&quot;


Set cmdDC = Server.CreateObject(&quot;ADODB.Command&quot;)
cmdDC.ActiveConnection = DataConnection

'-- default SQL
SQL = &quot;SELECT * FROM UserRegistration&quot;

If Request.Form(&quot;name&quot;) <> &quot;&quot; Then
SQL = &quot;SELECT * FROM Register WHERE &quot; &amp; _
&quot;Register.userID='&quot; &amp; strUserID &amp; &quot;' AND &quot; &amp; _
&quot;Register.password ='&quot; &amp; strPassword &amp; _
&quot;' OR Register.email ='&quot; &amp; strEmail &amp; &quot;'&quot;
End If

cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject(&quot;ADODB.Recordset&quot;)

'-- Cursor Type, Lock Type

'-- ForwardOnly 0 - ReadOnly 1
'-- KeySet 1 - Pessimistic 2
'-- Dynamic 2 - Optimistic 3
'-- Static 3 - BatchOptimistic 4


RecordSet.Open cmdDC, , 0, 2

'-- check to see if the user and password or
' e-mail address have registered before
If Not RecordSet.EOF Then
If RecordSet.fields(&quot;email&quot;)=strEmail Then
strError = &quot;<FONT FACE='ARIAL' SIZE='2'><B>&quot; &amp; _
&quot;Sorry this email has already been &quot; &amp; _
&quot;registered, please try again&quot; &amp; _
&quot;</B></FONT>&quot;
Else
'Redo page and say that this User name
'and Password are already taken
strError = &quot;<FONT FACE='ARIAL' SIZE='2'><B>&quot; &amp; _
&quot;Sorry this user name and password are &quot; &amp; _
&quot;already taken, please try again&quot; &amp; _
&quot;</B></FONT>&quot;
End If

Else
'-- Add new record to the database
Dim Dconn, sSQL
Set Dconn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Dconn.Open &quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=&quot; &amp; _
DatabasePath &amp; &quot;;&quot;

sSQL = &quot;INSERT INTO Register(name, email, userID, &quot; &amp; _
&quot;password, userLevel) VALUES ('&quot; &amp; strUserName &amp; _
&quot;','&quot; &amp; strEmail &amp; &quot;','&quot; &amp; strUserID &amp; _
&quot;','&quot; &amp; strPassword &amp; &quot;',1)&quot;
Dconn.Execute sSQL
Dconn.Close
Set Dconn = Nothing

'Forward the user to page to notify of authentication
Response.Redirect &quot;thankyou.asp&quot;
End If
Else
strError = &quot;Your passwords don't match&quot;
End If

'-- Close all connections
+++++++++ RecordSet.Close
Set RecordSet = Nothing

DataConnection.Close
Set DataConnection = Nothing

Else
'Tell them what they entered wrong
strError = &quot;Please fill in all the boxes&quot;
End If
End If

%>

 
Looks like you have created the recordset inside the if statement, and if it's not created (which is apparently what's happening), then you are trying to close something that was never created (because your if condition was false, and therefore the recordset was never created).

Try creating the recordset outside of the control statement, and then I think it should work just fine.

Hope it helps :)
Paul Prewett
 
Do you mean placing it after the last End If? At the botom of the page?
 
No, I mean when you create it in the first place, put it above the if statement that it's currently below. The reason is because that's the same control statement that the close statement is in.

Currently:
Code:
if
**somethingsomething**
  if
    creatingRecordset
  end if
closingRecordset
end if

Should be:
Code:
if
  creatingRecordset
  if
    **whateverelse**
  end if
  closingRecordset
end if

See that if, in the first one, if you never enter the second if statement, the recordset is never created, and therefore cannot be closed by the close statement?

Hope it helps! :)
Paul Prewett
 
Thanks it works but now for another glitch!

After a person registers I send them to a log in screen which is supposed to display to them their username and userlevel but it doesn't do it.

Any ideas? You have been very helpful.
 
oops here is the code

goes at the top of the page

<form action=&quot;index2.asp&quot; method=&quot;post&quot;>

<% If Session(&quot;userLevel&quot;) > 0 AND Request.Form(&quot;btnLogin&quot;) = &quot;Login&quot; _
AND Request.Form(&quot;txtName&quot;) <> &quot;&quot; AND _
Request.Form(&quot;txtPassword&quot;) <> &quot;&quot; Then
Response.write(&quot;<b>&quot; &amp; Request.Form(&quot;txtName&quot;))
Response.write(&quot;</b> is logged on.<BR>&quot;)
Response.write(&quot;User Access Level is: &quot;)
Response.write(RecordSet.Fields(&quot;userLevel&quot;) &amp; &quot;<BR>&quot;)
End If
%>

<html>
 
Well, there are a couple ways to do that. Probably the easiest way to do it would be to set a session variable with their username. Another advantage to that is that until they close their browser (or 20 minutes passes), that variable stays on the server.

You can set one by doing the following:
Code:
session(&quot;myVariableName&quot;) = theUsersId

And then you could retrieve it at a later date (or on the other page) by saying something like this:
Code:
theUsersId = session(&quot;myVariableName&quot;)

Then I'm guessing that your database has the user level stuff stored in it, so you create another recordset from the database (or better yet, store a static one in a session variable that you can access at any time), and then output that information to the screen.

The syntax for setting a session object is a little different compared to just a simple variable... you have to use the 'set' keyword like so
Code:
set session(&quot;myRecordsetName&quot;) = myRecordset

and then you get it back later by saying
Code:
set myRecordset = session(&quot;myRecordsetName&quot;)

I should note that I have been unable to get session variables or objects to work with PWS, only on NT or Win2000. I guess that has something to do with how PWS treats them, but I don't really know.

You may also look into a great little thing called disconnected recordsets. There is alot of information to be found on them on various websites, and I have found them to be an invaluable tool for making things such as logins and other such things persistent for user sessions. You can use them to store a long string of information just like a recordset from a database, only that there is no data connection that goes along with it!

Hope it helps! :)
Paul Prewett
 
Oops, sorry bout that long blurb there... I was assuming you were asking for advice since you didn't post any code...

Hmmmm... Hard for me to see anything wrong with that code. It looks ok on the surface, but without being able to see that context it's in, or the database layout, I'm not sure I could help much... :-(

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top