stopping users registering with the same username?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawtonl

    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=vbscri pt 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.CreateOb ject("ADODB.Con nection")
    Set ObjRS = Server.CreateOb ject("ADODB.Rec ordset")




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

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

    ObjRS.Open rsSQL, "DSN=Projec t"

    If ObjRS.RecordCou nt > 1 Then

    Response.Redire ct ("retry.html ")

    Else
    ObjConn.Open "DSN=projec t"
    ObjConn.Execute SQL

    End If

    ObjConn.Close
    Set ObjConn = nothing

    Response.Redire ct("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


  • only me

    #2
    Re: stopping users registering with the same username?

    Dim SQL 'A variable for the SQL statement
    Dim ObjConn 'A connection varaible
    Dim ObjRS

    Set ObjConn = Server.CreateOb ject("ADODB.Con nection")
    rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("s trUser") &
    "' "
    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.redire ct "retry.html "
    end if

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

    "lawtonl" <l.lawton@total ise.co.uk> wrote in message
    news:3f1af10d$0 $2877$afc38c87@ news.ukonline.c o.uk...[color=blue]
    > 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=vbscri pt 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.CreateOb ject("ADODB.Con nection")
    > Set ObjRS = Server.CreateOb ject("ADODB.Rec ordset")
    >
    >
    >
    >
    > rsSQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("s trUser")[/color]
    &[color=blue]
    > "' "
    >
    > SQL = "INSERT INTO tblUsers "
    > SQL = SQL & "(strUser, strPwd, strEmail) "
    > SQL = SQL & "VALUES ('"& Request.Form("s trUser") & "', '" &
    > Request.Form("s trPwd") & "','" & Request.Form("s trEmail") & "')"
    >
    > ObjRS.Open rsSQL, "DSN=Projec t"
    >
    > If ObjRS.RecordCou nt > 1 Then
    >
    > Response.Redire ct ("retry.html ")
    >
    > Else
    > ObjConn.Open "DSN=projec t"
    > ObjConn.Execute SQL
    >
    > End If
    >
    > ObjConn.Close
    > Set ObjConn = nothing
    >
    > Response.Redire ct("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
    >
    >[/color]


    Comment

    • martin

      #3
      Re: stopping users registering with the same username?

      > plus why not specify the field rather than use the * in the Select, those
      *[color=blue]
      > can bite you know (http://www.aspfaq.com/show.asp?id=2188)[/color]

      or just use count(*)


      "only me" <only_me@hotmai l.com> wrote in message
      news:XiESa.1762 $l63.23484@news fep4-glfd.server.ntl i.net...[color=blue]
      > correction[color=green]
      > > rsSQL = "SELECT * FROM tblUsers WHERE strUser='" &[/color][/color]
      Request.Form("s trUser")[color=blue]
      > &[color=green]
      > > "' "
      > > ObjRS = ObjConn.execute (sql) ' check for existing user[/color]
      >
      > should have been[color=green]
      > > SQL = "SELECT * FROM tblUsers WHERE strUser='" & Request.Form("s trUser")[/color][/color]
      &[color=blue][color=green]
      > > "' "
      > > ObjRS = ObjConn.execute (sql) ' check for existing user[/color]
      >
      > I was only trying to show the flow rather than provide syntactically[/color]
      correct[color=blue]
      > code - thats my story and I'm sticking to it
      >
      > plus why not specify the field rather than use the * in the Select, those[/color]
      *[color=blue]
      > can bite you know (http://www.aspfaq.com/show.asp?id=2188)
      >
      >
      > "only me" <only_me@hotmai l.com> wrote in message
      > news:QaESa.1752 $l63.23375@news fep4-glfd.server.ntl i.net...[color=green]
      > > Dim SQL 'A variable for the SQL statement
      > > Dim ObjConn 'A connection varaible
      > > Dim ObjRS
      > >
      > > Set ObjConn = Server.CreateOb ject("ADODB.Con nection")
      > > rsSQL = "SELECT * FROM tblUsers WHERE strUser='" &[/color][/color]
      Request.Form("s trUser")[color=blue]
      > &[color=green]
      > > "' "
      > > 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.redire ct "retry.html "
      > > end if
      > >
      > > I'd do it like this
      > > just my 2p worth
      > >
      > > "lawtonl" <l.lawton@total ise.co.uk> wrote in message
      > > news:3f1af10d$0 $2877$afc38c87@ news.ukonline.c o.uk...[color=darkred]
      > > > Hi, i've got a asp page to register a user and check that the username[/color][/color]
      > has[color=green][color=darkred]
      > > > not been previously registered, heres the code i have ... that doesnt[/color][/color]
      > work[color=green][color=darkred]
      > > >
      > > >
      > > > <SCRIPT LANGUAGE=vbscri pt 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.CreateOb ject("ADODB.Con nection")
      > > > Set ObjRS = Server.CreateOb ject("ADODB.Rec ordset")
      > > >
      > > >
      > > >
      > > >
      > > > rsSQL = "SELECT * FROM tblUsers WHERE strUser='" &[/color][/color]
      > Request.Form("s trUser")[color=green]
      > > &[color=darkred]
      > > > "' "
      > > >
      > > > SQL = "INSERT INTO tblUsers "
      > > > SQL = SQL & "(strUser, strPwd, strEmail) "
      > > > SQL = SQL & "VALUES ('"& Request.Form("s trUser") & "', '" &
      > > > Request.Form("s trPwd") & "','" & Request.Form("s trEmail") & "')"
      > > >
      > > > ObjRS.Open rsSQL, "DSN=Projec t"
      > > >
      > > > If ObjRS.RecordCou nt > 1 Then
      > > >
      > > > Response.Redire ct ("retry.html ")
      > > >
      > > > Else
      > > > ObjConn.Open "DSN=projec t"
      > > > ObjConn.Execute SQL
      > > >
      > > > End If
      > > >
      > > > ObjConn.Close
      > > > Set ObjConn = nothing
      > > >
      > > > Response.Redire ct("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
      > > >
      > > >[/color]
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...