469,281 Members | 2,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

stopping users registering with the same username?

Hi, i've got a asp page to register a user and check that the username has
not been previously registered, heres the code i have ... that doesnt work
<SCRIPT LANGUAGE=vbscript RUNAT=server>
'Adds a record to the table

Dim SQL 'A variable for the SQL statement
Dim ObjConn 'A connection varaible
Dim ObjRS
Set ObjConn = Server.CreateObject("ADODB.Connection")
Set ObjRS = Server.CreateObject("ADODB.Recordset")


rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("strUser") &
"' "

SQL = "INSERT INTO tblUsers "
SQL = SQL & "(strUser, strPwd, strEmail) "
SQL = SQL & "VALUES ('"& Request.Form("strUser") & "', '" &
Request.Form("strPwd") & "','" & Request.Form("strEmail") & "')"

ObjRS.Open rsSQL, "DSN=Project"

If ObjRS.RecordCount > 1 Then

Response.Redirect ("retry.html")

Else
ObjConn.Open "DSN=project"
ObjConn.Execute SQL

End If

ObjConn.Close
Set ObjConn = nothing

Response.Redirect("ok.html")

</script>

i am going the right way about it?
if so where have i gone wrong?
if not could someone please point me in the right direction
any help is appeciated
Regards
Jul 19 '05 #1
2 1704
Dim SQL 'A variable for the SQL statement
Dim ObjConn 'A connection varaible
Dim ObjRS

Set ObjConn = Server.CreateObject("ADODB.Connection")
rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("strUser") &
"' "
ObjRS = ObjConn.execute(sql) ' check for existing user
if ObjRS.EOF = True then ' it's OK its a new user so add them
SQL = "INSERT blah blah
ObjConn.execute(SQL)
else ' reject that user
response.redirect "retry.html"
end if

I'd do it like this
just my 2p worth

"lawtonl" <l.******@totalise.co.uk> wrote in message
news:3f**********************@news.ukonline.co.uk. ..
Hi, i've got a asp page to register a user and check that the username has
not been previously registered, heres the code i have ... that doesnt work
<SCRIPT LANGUAGE=vbscript RUNAT=server>
'Adds a record to the table

Dim SQL 'A variable for the SQL statement
Dim ObjConn 'A connection varaible
Dim ObjRS
Set ObjConn = Server.CreateObject("ADODB.Connection")
Set ObjRS = Server.CreateObject("ADODB.Recordset")


rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("strUser") & "' "

SQL = "INSERT INTO tblUsers "
SQL = SQL & "(strUser, strPwd, strEmail) "
SQL = SQL & "VALUES ('"& Request.Form("strUser") & "', '" &
Request.Form("strPwd") & "','" & Request.Form("strEmail") & "')"

ObjRS.Open rsSQL, "DSN=Project"

If ObjRS.RecordCount > 1 Then

Response.Redirect ("retry.html")

Else
ObjConn.Open "DSN=project"
ObjConn.Execute SQL

End If

ObjConn.Close
Set ObjConn = nothing

Response.Redirect("ok.html")

</script>

i am going the right way about it?
if so where have i gone wrong?
if not could someone please point me in the right direction
any help is appeciated
Regards

Jul 19 '05 #2
> plus why not specify the field rather than use the * in the Select, those
*
can bite you know (http://www.aspfaq.com/show.asp?id=2188)
or just use count(*)
"only me" <on*****@hotmail.com> wrote in message
news:Xi******************@newsfep4-glfd.server.ntli.net... correction
rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("strUser")
&
"' "
ObjRS = ObjConn.execute(sql) ' check for existing user
should have been
SQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("strUser") & "' "
ObjRS = ObjConn.execute(sql) ' check for existing user


I was only trying to show the flow rather than provide syntactically

correct code - thats my story and I'm sticking to it

plus why not specify the field rather than use the * in the Select, those * can bite you know (http://www.aspfaq.com/show.asp?id=2188)
"only me" <on*****@hotmail.com> wrote in message
news:Qa******************@newsfep4-glfd.server.ntli.net...
Dim SQL 'A variable for the SQL statement
Dim ObjConn 'A connection varaible
Dim ObjRS

Set ObjConn = Server.CreateObject("ADODB.Connection")
rsSQL = "SELECT * FROM tblUsers WHERE strUser='" &
Request.Form("strUser") &
"' "
ObjRS = ObjConn.execute(sql) ' check for existing user
if ObjRS.EOF = True then ' it's OK its a new user so add them
SQL = "INSERT blah blah
ObjConn.execute(SQL)
else ' reject that user
response.redirect "retry.html"
end if

I'd do it like this
just my 2p worth

"lawtonl" <l.******@totalise.co.uk> wrote in message
news:3f**********************@news.ukonline.co.uk. ..
Hi, i've got a asp page to register a user and check that the username

has not been previously registered, heres the code i have ... that doesnt work

<SCRIPT LANGUAGE=vbscript RUNAT=server>
'Adds a record to the table

Dim SQL 'A variable for the SQL statement
Dim ObjConn 'A connection varaible
Dim ObjRS
Set ObjConn = Server.CreateObject("ADODB.Connection")
Set ObjRS = Server.CreateObject("ADODB.Recordset")


rsSQL = "SELECT * FROM tblUsers WHERE strUser='" &

Request.Form("strUser")
&
"' "

SQL = "INSERT INTO tblUsers "
SQL = SQL & "(strUser, strPwd, strEmail) "
SQL = SQL & "VALUES ('"& Request.Form("strUser") & "', '" &
Request.Form("strPwd") & "','" & Request.Form("strEmail") & "')"

ObjRS.Open rsSQL, "DSN=Project"

If ObjRS.RecordCount > 1 Then

Response.Redirect ("retry.html")

Else
ObjConn.Open "DSN=project"
ObjConn.Execute SQL

End If

ObjConn.Close
Set ObjConn = nothing

Response.Redirect("ok.html")

</script>

i am going the right way about it?
if so where have i gone wrong?
if not could someone please point me in the right direction
any help is appeciated
Regards



Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Gerry Abbott | last post: by
10 posts views Thread by Conformix Sales | last post: by
6 posts views Thread by D | last post: by
1 post views Thread by pmorrison | last post: by
1 post views Thread by shivkumar2004 | last post: by
10 posts views Thread by =?Utf-8?B?R3JlZw==?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.