Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBScript runtime (0x800A000D) Type mismatch: 'Response.Cookies'

356 views
Skip to first unread message

Sergo

unread,
Sep 22, 2000, 3:00:00 AM9/22/00
to

Hello, I'm working on the membership based website (for my school), in
order for people to able to use the site they must first register,
recieve a username and password. I thought I was done, everything was
working, when I realized that my code allows multiple users with the
same username, so decided to add the followin piece of code to the part
that validates user's info:

''CHECK IF USERNAME ALREADY EXISTS
Dim usernameCheckRS
Set usernameCheckRS = Conn.Execute("SELECT id FROM ob_webuser" &_
"WHERE username = '" & username & "'")

If Not usernameCheckRS.EOF Then
error_flag = 1
err_msg = err_msg & "Username that you`ve seleceted is already" &_
" taken, please choose another username<BR>"

usernameCheckRS.close
End If


Here is how everything works:
register.asp, when button "SAVE" is clicked, calls for file
"validate_user_info.inc"(this is where I added the code from above), it
validates if user's info is valid, if it's not it shows an error message
and if it is, register.asp calls for file "save_user.inc" which saves
the user to the database, and then register.asp suposed to set the
cookie and redirect the user to main.asp.
Well befor I added the code from above, everything worked flawlesly, but
now after I added it, it works for validating whether the username
exists, and saves the new user to the database, BUT instead of setting
the cookie and redirecting to main.asp it shows the following error
message:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'Response.Cookies'
/EDP_Current/register.asp, line 84


the funy thing is, when I remove the code that validates if username
exists - everything works again.

Here a piece from register.asp that does what I described:
----------------------------------------------------------

<%
'' SAVE USER INFO
If Request("action") = "SAVE" Then
%>
<!-- #include file = "includes/validate_user_info.inc" -->
<%
'' no errors save user data
If error_flag = 0 Then
%>
<!-- #include file = "includes/save_user.inc" -->
<%
Response.Cookies("uid") = userId
Response.Redirect "main.asp"
End If
End If
%>

Here is validate_user_info.inc :
--------------------------------

<%
err_str = ""

''NO USERNAME WAS PROVIDED
If username = empty Then
error_flag = 1
err_msg = err_msg & "Username is missing<BR>"
End If

''NO PASSWORD WAS PROVIDED
If pwd = empty Then
error_flag = 1
err_msg = err_msg & "Password is missing<BR>"
End If

''PASSWORDS DO NOT MATCH
If repwd <> pwd Then
error_flag = 1
err_msg = err_msg & "Passwords don't match<BR>"
End If

''NO FIRSTNAME WAS PROVIDED
If firstname = empty Then
error_flag = 1
err_msg = err_msg & "First name is missing<BR>"
End If

''NO LASTNAME WAS PROVIDED
If lastname = empty Then
error_flag = 1
err_msg = err_msg & "Last name is missing<BR>"
End If

''NO EMAIL ADDRESS WAS PROVIDED
If email = empty Then
error_flag = 1
err_msg = err_msg & "Email is missing<BR>"
End If

''NO YEAR OF BIRTH WAS PROVIDED
If year_of_birth = empty Then
error_flag = 1
err_msg = err_msg & "Year of birth is missing<BR>"

'''year of birth is not all numeric characters
ElseIf not isNumeric(year_of_birth) Then
error_flag = 1
err_msg = err_msg & "Year of birth is invalid<BR>"
End If

''CHECK IF USERNAME ALREADY EXISTS
Dim usernameCheckRS
Set usernameCheckRS = Conn.Execute("SELECT id FROM ob_webuser WHERE
username = '" & username & "'")

If Not usernameCheckRS.EOF Then
error_flag = 1
err_msg = err_msg & "Username that you`ve seleceted is already
taken, please choose another username<BR>"

usernameCheckRS.close
End If

%>

Here is save_user.inc :
-----------------------

<%

'' check for empty values and replace them with NULLs
If address = Empty or address = "" Then
i_address = "NULL"
Else
i_address = "'" & address & "'"
End If
If city = Empty or city = "" Then
i_city = "NULL"
Else
i_city = "'" & city & "'"
End If
If state = Empty or state = "" Then
i_state = "NULL"
Else
i_state = "'" & state & "'"
End If
If zip = Empty or zip = "" Then
i_zip = "NULL"
Else
i_zip = "'" & zip & "'"
End If

'' UPDATE
If CInt(userId) > 0 Then
sqlString = "update ob_webuser " & _
"set password = '" & pwd & "', " & _
"first_name = '" & firstname & "', " & _
"last_name = '" & lastname & "', " & _
"email = '" & email & "', " & _
"year_of_birth = " & year_of_birth & ", " & _
"address = " & i_zip & ", " & _
"city = " & i_city & ", " & _
"state = " & i_state & ", " & _
"zip = " & i_zip & " " & _
"where id = " & userId

Conn.Execute(sqlString)

'' INSERT
Else
sqlString = "insert into ob_webuser " & _
"values('" & username & "','" & pwd & "'," & _
"'" & firstname & "','" & lastname & "'," & _
"'" & email & "'," & year_of_birth & "," & _
i_address & "," & i_city & "," & i_state & "," & _
i_zip & ",2 )"
Conn.Execute(sqlString)

''evrything untill this part, works
'' get new user id
set uidRS = Conn.execute("select @@IDENTITY 'id'")
If not uidRS.eof Then
userId = uidRS("id")
End If
End If

%>

I'm running IIS 5.0 and MS SQL Server 7.0 on Win2000 Pro

Any insight and/or ideas would be greatly appretiated.

THANKS!!!!

--
///************************************************
// "Righteousness Exalteth A Nation!
// The righteousness cannot be forgotten
// and the glory cannot be blocken out..."
///**************************************************

Chad Myers

unread,
Sep 22, 2000, 3:00:00 AM9/22/00
to
Which line is the specific error occuring on?

Is it the Response.Cookies("uid")= userid?

What is the value of "userid"?

Put a response.write before setting the cookie and
let us know what the value of userid is. I suspect
that userid may be NULL

-Chad

"Sergo" <badm...@yahoo.com> wrote in message
news:uirHneI...@cppssbbsa02.microsoft.com...

Sergo

unread,
Sep 23, 2000, 12:58:42 AM9/23/00
to

"Chad Myers" <cmy...@NOSPAM.austin.rr.com> wrote in message
news:egWhxHL...@cppssbbsa02.microsoft.com...


>
> Is it the Response.Cookies("uid")= userid?
>

yes, that's the one


> What is the value of "userid"?
>

the value of userid is the numeric value from the @@IDENTITY field from
ob_webuser table (@@IDENTITY is automaticaly assigned to the user by SQL
Server when he/she is added to the db):

'' get new user id
set uidRS = Conn.execute("select @@IDENTITY 'id'")
If not uidRS.eof Then
userId = uidRS("id")
End If


this is the last piece of code in the save_user.inc and everything
before it works, user IS being added to the db, and I manualy checked in
SQL Server - @@IDENTITY IS assigned, but for some reason it can't select
it!


> Put a response.write before setting the cookie
>

I'll try that, thanks.

Sergo

Sergo

unread,
Sep 23, 2000, 2:26:46 AM9/23/00
to

ok, after some playing around I confirmed, that yes, userId is NULL, to
be precice, this part:

'' get new user id
set uidRS = Conn.execute("select @@IDENTITY 'id'")
If not uidRS.eof Then
userId = uidRS("id")
End If


returns userId as NULL,

BUT WHY???!!! I just don't get it, because all the info, including the
IDENTITY, IS added to the ob_webuser table (I did "SELECT * FROM
ob_webuser" in SQL Server)


Sergo


Chad Myers

unread,
Sep 25, 2000, 3:00:00 AM9/25/00
to
Try "select id = @@IDENTITY"

Perhaps you should consider using Stored Procedures to
do this kind of thing? Stored procs are preferred over
in-line SQL statements for maintenance and speed's sake.

Your stored proc would be something like this:
--------------------------------
CREATE PROCEDURE spAddNewUser
@Username as varchar(14),
@Password as varchar(14),
@NewID as int OUTPUT
AS

INSERT INTO ob_webuser (Username, Password)
VALUES (@Username, @Password)
SELECT @NewID = @@IDENTITY
--------------------------------

@NewID would then equal the value of the new user.

Use the ADODB.Command object to call parameterized
stored procedures and set and get the parameters.

-Chad

"Sergo" <badm...@yahoo.com> wrote in message

news:u$wUscSJAHA.241@cppssbbsa05...

0 new messages