Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Using Username as a unique key


Message #1 by "Brad" <insuran@m...> on Fri, 19 May 2000 2:43:52
I have just brought both Beginning and Professional Active server pages.. I 

find them both very helpful and hope to read all of them both soon.. But i 

do have a very minor question.  I am using an SQL database, which i created 

in access 2000 and upsized to SQL 7.0.  I set the primary key as the 

username.  But the problem is i have registred the same username 5 times.  

I want this a unique value.. In the registration process people enter in 

thier info and it is error checked client side by javascript, then passed 

on to another page were they verify thier info.  I would like to create an 

"if then statement" such that if the username they have choosen exists in 

the database then they will see a message "username already take please hit 

back and choose another".. Then if the username they have selected doesnt 

exist in the database then the verifcation page goes ahead and loads...  

Please help me out.. thanks..



A new and stupid programmer

Brad

Message #2 by "Philip.Ware" <Philip.Ware@e...> on Fri, 19 May 2000 09:43:11 +0100
You could use:



myrecordset.open "Select * from Users where UserName = "'" & username & "'"



' did we find anybody with that name?

if myrecordset.recordcount > 0 then

	' something found in the database with that name

	....

else

	' nobody found continue...

	...

end if



hope this helps,

Phil.



> -----Original Message-----

> From: Brad 

> Sent: 19 May 2000 03:44

> To: ASP Databases

> Subject: [asp_databases] Using Username as a unique key

> 

> 

> I have just brought both Beginning and Professional Active 

> server pages.. I 

> find them both very helpful and hope to read all of them both 

> soon.. But i 

> do have a very minor question.  I am using an SQL database, 

> which i created 

> in access 2000 and upsized to SQL 7.0.  I set the primary key as the 

> username.  But the problem is i have registred the same 

> username 5 times.  

> I want this a unique value.. In the registration process 

> people enter in 

> thier info and it is error checked client side by javascript, 

> then passed 

> on to another page were they verify thier info.  I would like 

> to create an 

> "if then statement" such that if the username they have 

> choosen exists in 

> the database then they will see a message "username already 

> take please hit 

> back and choose another".. Then if the username they have 

> selected doesnt 

> exist in the database then the verifcation page goes ahead 

> and loads...  

> Please help me out.. thanks..

> 

> A new and stupid programmer

> Brad

Message #3 by "Brad Libby" <insuran@m...> on Fri, 19 May 2000 09:41:16 -0400
This is the script i am using... I keep getting the following error..



"Microsoft VBScript runtime error '800a01a8'

Object required: ''



/jatohighlands/handicap/verify.asp, line 13"







This is the source for the page... Please help me out.. what is going on?

Prob something little that i have left out... I am trying to check if a

"username" is already used in table "handicap"



 <% dim strusername, strpassword, stremail

strusername = request.form("username")

strpassword = request.form("password")

stremail = request.form("email")

%>

<%

Dim connstring, my_conn, myrecordset

connstring = "DRIVER={SQL

Server};SERVER=SQLDATA;LANGUAGE=us_english;DATABASE=*******;UID=*******;PWD

********"

set my_conn=server.createObject("adodb.connection")

set my_rs= Server.CreateObject("ADODB.recordset")

my_Conn.Open ConnString



myrecordset.open "Select username from handicap where username = "' &

strusername & '""

if myrecordset.recordcount > 0 then %>

<body bgcolor = 114B0f>



<table border="0" cellpadding="0" cellspacing="0" width="650">

  <tr>

    <td><font size=4 color = white>Username has already been used, Please

hit Back in your Browser and enter a new Username. Thank You For using

      JaToHighlands</font></td>

  </tr>

</table>

<%else%>





<table border="0" cellpadding="0" cellspacing="0" width="652">

  <tr>

    <td width="64"></td>

    <td width="576"></td>

    <td width="6"></td>

  </tr>



  <tr>

    <td width="64"></td>

    <td width="576"><b><font size="4">Please verify the following

information is

      correct. If it is not please hit the "Back" button in your

      Browser and correct the information...</font></b></td>

    <td width="6"></td>

  </tr>

  <tr>

    <td width="64"></td>

    <td width="576"> </td>

    <td width="6"></td>

  </tr>

  <tr>

    <td width="64"></td>

    <td width="576">

      <table border="0" cellpadding="0" cellspacing="0" width="100%">

        <tr>

          <td width="22%"><font size="4">Username</font></td>

          <td width="78%"><%=strusername%></td>

        </tr>

        <tr>

          <td width="22%"><font size="4">Password</font></td>

          <td width="78%"><b><i><font size="4">VERIFIED</font></i></b></td>

        </tr>

        <tr>

          <td width="22%"><font size="4">Email</font></td>

          <td width="78%"><%=stremail%></td>

        </tr>

      </table>

    </td>

    <td width="6"></td>

  </tr>

  <tr>

    <td width="64"></td>

    <td width="576">  </td>

    <td width="6"></td>

  </tr>

  <tr>

    <td width="64"></td>

    <td width="576"><a href="thanks.asp"><img border="0"

src="../images/continue.gif"></a></td>

    <td width="6"></td>

  </tr>

</table>





<% dim objdictionary

set objdictionary = createobject("scripting.dictionary")

objdictionary.add "username", strusername

objdictionary.add "password", strpassword

objdictionary.add "email", stremail

set session("mydictionary") = objdictionary

%>

<%end if%>

</body>







Message #4 by "Cory Koski" <ckoski@w...> on Fri, 19 May 2000 16:2:17

> A good way to do this (since you're using SQL 7.0) is to use a stored proc and build a VB script function that you pass the
username and the function will return back true or false...

> 

> your stored procedure should look something like this:

> 

> -------------------------------

> Create Procedure listingexists

>  ( @name varchar(100) )

> As

>  if exists (SELECT userid FROM user_table WHERE userid = @name)

>   return 1

>  else

>   return 0

> -----------------------

> your ASP VB script function should look something like this:

> ----------------------------------

> 

> <!--#include virtual="path-to-includes/adovbs.inc"-->

> <%

> Function Exists(name)

>   Dim cmd, dbConnection

>  

>   set cmd = Server.CreateObject("ADODB.Command")

>   set dbConnection = Server.CreateObject("ADODB.Connection")

>   dbConnection.Open = YOUR_DSN_CONNECTION_STRING

>   

>   With cmd

>    .ActiveConnection = dbConnection

>    .CommandType = adCmdStoredProc

>    .CommandText = "listingexists"

>   

>    .Parameters.Append .CreateParameter ("Return_Value", adInteger, adParamReturnValue)

>    .Parameters.Append .CreateParameter ("name",adVarChar,adParamInput,100,name)

>    .Execute

>   end with

> 

>   Exists = CBool(cmd.Parameters("Return_Value")) 

>   set cmd = nothing

>   dbConnction.Close

>   set dbConnetion = Nothing

> 

>  End Function

> %>

> ----------------------------------

> 

> I know this looks like overkill at first, but it is a middle-tier design (which MS recommends).

> 

> Good luck!

> 

> Cory

> 

> 

> ----- Original Message ----- 

> From: "Brad" 

> To: "ASP Databases" <asp_databases@p...>

> Sent: Friday, May 19, 2000 2:43 AM

> Subject: [asp_databases] Using Username as a unique key

> 

> 

> > I have just brought both Beginning and Professional Active server pages.. I

> > find them both very helpful and hope to read all of them both soon.. But i

> > do have a very minor question.  I am using an SQL database, which i created

> > in access 2000 and upsized to SQL 7.0.  I set the primary key as the 

> > username.  But the problem is i have registred the same username 5 times.

> > I want this a unique value.. In the registration process people enter in

> > thier info and it is error checked client side by javascript, then passed

> > on to another page were they verify thier info.  I would like to create an

> > "if then statement" such that if the username they have choosen exists in

> > the database then they will see a message "username already take please hit

> > back and choose another".. Then if the username they have selected doesnt

> > exist in the database then the verifcation page goes ahead and loads...

> > Please help me out.. thanks..

> > 

> > A new and stupid programmer

> > Brad

> > 

Message #5 by "Joycelyn Yeo" <gummy_san@h...> on Fri, 19 May 2000 07:57:43 PDT
Hi!

i m not sure where your error is.can you tell me the swpecific line?

but from what i counted ,it should be



>myrecordset.open "Select username from handicap where username = "' &

>strusername & '""



right??

ok.try this



>myrecordset.open "Select username from handicap where username = "' &

>strusername & '"" , my_Conn



-->add the connection object behind.



All the BEST!!



Joycelyn



>From: "Brad Libby" 

>Reply-To: "ASP Databases" <asp_databases@p...>

>To: "ASP Databases" <asp_databases@p...>

>Subject: [asp_databases]  Using Username as a unique key

>Date: Fri, 19 May 2000 09:41:16 -0400

>

>This is the script i am using... I keep getting the following error..

>

>"Microsoft VBScript runtime error '800a01a8'

>Object required: ''

>

>/jatohighlands/handicap/verify.asp, line 13"

>

>

>

>This is the source for the page... Please help me out.. what is going on?

>Prob something little that i have left out... I am trying to check if a

>"username" is already used in table "handicap"

>

>  <% dim strusername, strpassword, stremail

>strusername = request.form("username")

>strpassword = request.form("password")

>stremail = request.form("email")

>%>

><%

>Dim connstring, my_conn, myrecordset

>connstring = "DRIVER={SQL

>Server};SERVER=SQLDATA;LANGUAGE=us_english;DATABASE=*******;UID=*******;PWD

>********"

>set my_conn=server.createObject("adodb.connection")

>set my_rs= Server.CreateObject("ADODB.recordset")

>my_Conn.Open ConnString

>

>myrecordset.open "Select username from handicap where username = "' &

>strusername & '""

>if myrecordset.recordcount > 0 then %>

><body bgcolor = 114B0f>

>

><table border="0" cellpadding="0" cellspacing="0" width="650">

>   <tr>

>     <td><font size=4 color = white>Username has already been used, Please

>hit Back in your Browser and enter a new Username. Thank You For using

>       JaToHighlands</font></td>

>   </tr>

></table>

><%else%>

>

>

><table border="0" cellpadding="0" cellspacing="0" width="652">

>   <tr>

>     <td width="64"></td>

>     <td width="576"></td>

>     <td width="6"></td>

>   </tr>

>

>   <tr>

>     <td width="64"></td>

>     <td width="576"><b><font size="4">Please verify the following

>information is

>       correct. If it is not please hit the "Back" button in your

>       Browser and correct the information...</font></b></td>

>     <td width="6"></td>

>   </tr>

>   <tr>

>     <td width="64"></td>

>     <td width="576"> </td>

>     <td width="6"></td>

>   </tr>

>   <tr>

>     <td width="64"></td>

>     <td width="576">

>       <table border="0" cellpadding="0" cellspacing="0" width="100%">

>         <tr>

>           <td width="22%"><font size="4">Username</font></td>

>           <td width="78%"><%=strusername%></td>

>         </tr>

>         <tr>

>           <td width="22%"><font size="4">Password</font></td>

>           <td width="78%"><b><i><font 

>size="4">VERIFIED</font></i></b></td>

>         </tr>

>         <tr>

>           <td width="22%"><font size="4">Email</font></td>

>           <td width="78%"><%=stremail%></td>

>         </tr>

>       </table>

>     </td>

>     <td width="6"></td>

>   </tr>

>   <tr>

>     <td width="64"></td>

>     <td width="576">  </td>

>     <td width="6"></td>

>   </tr>

>   <tr>

>     <td width="64"></td>

>     <td width="576"><a href="thanks.asp"><img border="0"

>src="../images/continue.gif"></a></td>

>     <td width="6"></td>

>   </tr>

></table>

>

>

><% dim objdictionary

>set objdictionary = createobject("scripting.dictionary")

>objdictionary.add "username", strusername

>objdictionary.add "password", strpassword

>objdictionary.add "email", stremail

>set session("mydictionary") = objdictionary

>%>

><%end if%>

></body>

>

>
Message #6 by "Jessica Chen" <jchen@g...> on Fri, 19 May 2000 11:14:05 -0400
Try this:

myrecordset.open "Select username from handicap where username =3D '" &

strusername &  "'"



Jessica







From: Joycelyn Yeo [mailto:gummy_san@h...]

Sent: Friday, May 19, 2000 10:58 AM

To: ASP Databases

Subject: [asp_databases] Re: Using Username as a unique key





Hi!

i m not sure where your error is.can you tell me the swpecific line?

but from what i counted ,it should be



>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '""



right??

ok.try this



>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '"" , my_Conn



-->add the connection object behind.



All the BEST!!



Joycelyn



>From: "Brad Libby"

>Reply-To: "ASP Databases" <asp_databases@p...>

>To: "ASP Databases" <asp_databases@p...>

>Subject: [asp_databases]  Using Username as a unique key

>Date: Fri, 19 May 2000 09:41:16 -0400

>

>This is the script i am using... I keep getting the following error..

>

>"Microsoft VBScript runtime error '800a01a8'

>Object required: ''

>

>/jatohighlands/handicap/verify.asp, line 13"

>

>

>

>This is the source for the page... Please help me out.. what is going on

?

>Prob something little that i have left out... I am trying to check if a

>"username" is already used in table "handicap"

>

>  <% dim strusername, strpassword, stremail

>strusername =3D request.form("username")

>strpassword =3D request.form("password")

>stremail =3D request.form("email")

>%>

><%

>Dim connstring, my_conn, myrecordset

>connstring =3D "DRIVER=3D{SQL

>Server};SERVER=3DSQLDATA;LANGUAGE=3Dus_english;DATABASE=3D*******;UID=3D

*******;PWD

=3D

>********"

>set my_conn=3Dserver.createObject("adodb.connection")

>set my_rs=3D Server.CreateObject("ADODB.recordset")

>my_Conn.Open ConnString

>

>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '""

>if myrecordset.recordcount > 0 then %>

><body bgcolor =3D 114B0f>

>

><table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"650">

>   <tr>

>     <td><font size=3D4 color =3D white>Username has already been used, 

Please

>hit Back in your Browser and enter a new Username. Thank You For using

>       JaToHighlands</font></td>

>   </tr>

></table>

><%else%>

>

>

><table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"652">

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"></td>

>     <td width=3D"6"></td>

>   </tr>

>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"><b><font size=3D"4">Please verify the following

>information is

>       correct. If it is not please hit the "Back" button in y

our

>       Browser and correct the information...</font></b></td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"> </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576">

>       <table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"

100%">

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Username</font></td>

>           <td width=3D"78%"><%=3Dstrusername%></td>

>         </tr>

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Password</font></td>

>           <td width=3D"78%"><b><i><font

>size=3D"4">VERIFIED</font></i></b></td>

>         </tr>

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Email</font></td>

>           <td width=3D"78%"><%=3Dstremail%></td>

>         </tr>

>       </table>

>     </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576">  </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"><a href=3D"thanks.asp"><img border=3D"0"

>src=3D"../images/continue.gif"></a></td>

>     <td width=3D"6"></td>

>   </tr>

></table>

>

>

><% dim objdictionary

>set objdictionary =3D createobject("scripting.dictionary")

>objdictionary.add "username", strusername

>objdictionary.add "password", strpassword

>objdictionary.add "email", stremail

>set session("mydictionary") =3D objdictionary

>%>

><%end if%>

></body>

>

>

---

ASPToday brings the essence of the Wrox Programmer to Programmer=99 philo

sophy

to you through the Web. Every weekday, this is where you will find a new,

original article by ASP programmers for ASP programmers, for free. ASPTod

ay

at http://www.asptoday.com

---

You are currently subscribed to asp_databases

To unsubscribe send a blank email to leave-asp_databases-5284E@p...

om



Message #7 by Anil Budhkar <anilb@m...> on Mon, 22 May 2000 11:36:58 +0530
I think from your code that, you have two variables for recordset. One

'myrecordset' and other which you are setting 'my_rs'. You are setting my

_rs

and trying to access myrecordset. Check if this is the problem?



All the best.



Anil





-----Original Message-----

From: Joycelyn Yeo 

Sent: Friday, May 19, 2000 8:28 PM

To: ASP Databases

Subject: [asp_databases] Re: Using Username as a unique key





Hi!

i m not sure where your error is.can you tell me the swpecific line?

but from what i counted ,it should be



>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '""



right??

ok.try this



>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '"" , my_Conn



-->add the connection object behind.



All the BEST!!



Joycelyn



>From: "Brad Libby"

>Reply-To: "ASP Databases" <asp_databases@p...>

>To: "ASP Databases" <asp_databases@p...>

>Subject: [asp_databases]  Using Username as a unique key

>Date: Fri, 19 May 2000 09:41:16 -0400

>

>This is the script i am using... I keep getting the following error..

>

>"Microsoft VBScript runtime error '800a01a8'

>Object required: ''

>

>/jatohighlands/handicap/verify.asp, line 13"

>

>

>

>This is the source for the page... Please help me out.. what is going on

?

>Prob something little that i have left out... I am trying to check if a

>"username" is already used in table "handicap"

>

>  <% dim strusername, strpassword, stremail

>strusername =3D request.form("username")

>strpassword =3D request.form("password")

>stremail =3D request.form("email")

>%>

><%

>Dim connstring, my_conn, myrecordset

>connstring =3D "DRIVER=3D{SQL

>Server};SERVER=3DSQLDATA;LANGUAGE=3Dus_english;DATABASE=3D*******;UID=3D

*******;PWD

=3D

>********"

>set my_conn=3Dserver.createObject("adodb.connection")

>set my_rs=3D Server.CreateObject("ADODB.recordset")

>my_Conn.Open ConnString

>

>myrecordset.open "Select username from handicap where username =3D "' &

>strusername & '""

>if myrecordset.recordcount > 0 then %>

><body bgcolor =3D 114B0f>

>

><table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"650">

>   <tr>

>     <td><font size=3D4 color =3D white>Username has already been used, 

Please

>hit Back in your Browser and enter a new Username. Thank You For using

>       JaToHighlands</font></td>

>   </tr>

></table>

><%else%>

>

>

><table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"652">

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"></td>

>     <td width=3D"6"></td>

>   </tr>

>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"><b><font size=3D"4">Please verify the following

>information is

>       correct. If it is not please hit the "Back" button in y

our

>       Browser and correct the information...</font></b></td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"> </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576">

>       <table border=3D"0" cellpadding=3D"0" cellspacing=3D"0" width=3D"

100%">

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Username</font></td>

>           <td width=3D"78%"><%=3Dstrusername%></td>

>         </tr>

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Password</font></td>

>           <td width=3D"78%"><b><i><font

>size=3D"4">VERIFIED</font></i></b></td>

>         </tr>

>         <tr>

>           <td width=3D"22%"><font size=3D"4">Email</font></td>

>           <td width=3D"78%"><%=3Dstremail%></td>

>         </tr>

>       </table>

>     </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576">  </td>

>     <td width=3D"6"></td>

>   </tr>

>   <tr>

>     <td width=3D"64"></td>

>     <td width=3D"576"><a href=3D"thanks.asp"><img border=3D"0"

>src=3D"../images/continue.gif"></a></td>

>     <td width=3D"6"></td>

>   </tr>

></table>

>

>

><% dim objdictionary

>set objdictionary =3D createobject("scripting.dictionary")

>objdictionary.add "username", strusername

>objdictionary.add "password", strpassword

>objdictionary.add "email", stremail

>set session("mydictionary") =3D objdictionary

>%>

><%end if%>

></body>

>

>


  Return to Index