PDA

View Full Version : code error, please help


scroots
11-16-2002, 04:25 PM
i have the following code:

<% @LANGUAGE = VBSCRIPT %>
<% Option Explicit %>
<%
Dim uname, pword
uname = Request.Form("uname")
pword = Request.Form("pword")

Dim cmdGetUser, rsGetUser
Set cmdGetUser = Server.CreateObject.Command
cmdGetUSer.ActiveConnection = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("loginauth.mdb")
cmdGetUser.CommandText = "SELECT * FROM tbl_Users WHERE tblUsers.username = '" & uname '""
cmdGetUser.CommandType = adCmdText

Set rsGetUser = cmdGetUser.Execute

Set cmdGetUser = Nothing

While Not rsGetUser.EOF

If UCase(uname) = Ucase(rsGetUser("username")) Then
If UCase(pword) = Ucase(rsGetUser("password")) Then
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
Else
Response.Redirect "plogin.asp?error=password"
End If
Else
Response.Redirect "plogin.asp?error=username"
End If

rsGetUser.Close()
Set rsGetUser = Nothing
%>


and it produces the following error:
Microsoft VBScript compilation error '800a03fa'

Expected 'Wend'

/Password Web/checklogin.asp, line 32

i have highlighted line 32, can anoyone help? i don`t even know what a wend is.
thanks in advance
scroots

whammy
11-16-2002, 04:44 PM
Wend

is the command to end a While loop. Which you have started but not ended.

:)

While Not rsGetUser.EOF

If UCase(uname) = Ucase(rsGetUser("username")) Then
If UCase(pword) = Ucase(rsGetUser("password")) Then
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
Else
Response.Redirect "plogin.asp?error=password"
End If
Else
Response.Redirect "plogin.asp?error=username"
End If

Wend

Actually, you'd be better off letting SQL do the work for you:

"SELECT * FROM tablename where username = '" & username & "' AND password = '" & password & "'"

Then just say

IF NOT rsGetUser.EOF
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
ELSE
Response.Redirect "plogin.asp?error=nomatch"
END IF

scroots
11-16-2002, 05:48 PM
thanks whammy, your new suggestion about sql is better and thie fix, is top.
thanks
scroots

dominicall
11-16-2002, 07:44 PM
Hi scroots

whammy's suggestion is definitely the way to go... one thing I did notice in your code though is the lack of rs.MoveNext, as below...While Not rsGetUser.EOF

If UCase(uname) = Ucase(rsGetUser("username")) Then
If UCase(pword) = Ucase(rsGetUser("password")) Then
Session("UserID") = rsGetUser("UserID")
Response.Redirect "success.asp"
Else
Response.Redirect "plogin.asp?error=password"
End If
Else
Response.Redirect "plogin.asp?error=username"
End If

rsGetUser.MoveNext

Wend

rsGetUser.Close()
Set rsGetUser = Nothing If you forget to the use MoveNext then you'll end up loading up the server hugely... we've all done it - I do it regularly - LOL

Dominic :D

whammy
11-16-2002, 08:09 PM
Haha yeah, we all HAVE done it. That kills the server... if I MUST loop, I usually write the loop FIRST, like this, so I don't forget anything:

Do WHILE NOT rs.EOF

rs.MoveNext
Loop

:)

scroots
11-17-2002, 07:49 PM
thank you!
cheers:thumbsup:

scroots