Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Preventing duplicates


Message #1 by "craig" <cn60@m...> on Mon, 12 Aug 2002 17:42:18
Hello,

    below is code for a form to write to an access 2000 database.  
Everything works fine.  But two questions came up that i can not answer. 
1) how do i prevent duplicate emails from being entered? 2) how do i 
validate the emails being entered?  This is my first attempt at this and i 
am struggling to find an answer. i have read a few articles, but at this 
point they are a little over my head. if you could point me to an article 
that is easy to understand at my level, i would appreciate it. or any 
insight at all.

thanks,
craig




 <% 
	IF request.form ("Message")="True" THEN
	strTB1=request.form("FirstTextBox")
	strTB2=request.form("SecondTextBox")
	strTB3=request.form("EMail")
	
	
	'Opening the DataBase Object
	set objConn = server.createobject("ADODB.Connection")
    objConn.Open "DSN=info"
	set cm = Server.CreateObject("ADODB.Command")
	cm.ActiveConnection = objConn
	
	cm.CommandText ="INSERT INTO SampleDb(TB1,TB2,TB3) VALUES (?,?,?)" 
	
	
		'First Text Box Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB1)
	cm.parameters.append objparam

	'Second Text Box Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB2)
	cm.parameters.append objparam

	'Third Text Box Value Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB3)
	cm.parameters.append objparam

	
	

	
	cm.execute
	response.write("Thank you!")  
ELSE%>
Message #2 by Sam Clohesy <sam@e...> on Mon, 12 Aug 2002 18:03:09 +0100
Use javascipt to validate the address (loads of really useful stuff @
javascripts.internet.com) then do another select before your insert, for
example:

<%
set objrsTest = server.createObject("ADODB.Re...etc etc)
strSQL = "select * from mytable = where email = " & strTB3
'open rs and connection etc
Then check if the recordset is empty:

If not objRsTest.EOF and not objRsTest.BOF Then

'Do your insert stuff

Else
response.write "Duplicate email"
End if
%>

Probably a better way to do this but this is how I would approach it.

thanks
Sam





-----Original Message-----
From: craig [mailto:cn60@m...]
Sent: 12 August 2002 18:42
To: ASP Databases
Subject: [asp_databases] Preventing duplicates


Hello,

    below is code for a form to write to an access 2000 database.  
Everything works fine.  But two questions came up that i can not answer. 
1) how do i prevent duplicate emails from being entered? 2) how do i 
validate the emails being entered?  This is my first attempt at this and i 
am struggling to find an answer. i have read a few articles, but at this 
point they are a little over my head. if you could point me to an article 
that is easy to understand at my level, i would appreciate it. or any 
insight at all.

thanks,
craig




 <% 
	IF request.form ("Message")="True" THEN
	strTB1=request.form("FirstTextBox")
	strTB2=request.form("SecondTextBox")
	strTB3=request.form("EMail")
	
	
	'Opening the DataBase Object
	set objConn = server.createobject("ADODB.Connection")
    objConn.Open "DSN=info"
	set cm = Server.CreateObject("ADODB.Command")
	cm.ActiveConnection = objConn
	
	cm.CommandText ="INSERT INTO SampleDb(TB1,TB2,TB3) VALUES (?,?,?)" 
	
	
		'First Text Box Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB1)
	cm.parameters.append objparam

	'Second Text Box Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB2)
	cm.parameters.append objparam

	'Third Text Box Value Parameter Statement
	set objparam=cm.createparameter(, 200, , 255, strTB3)
	cm.parameters.append objparam

	
	

	
	cm.execute
	response.write("Thank you!")  
ELSE%>
Message #3 by "Gavin Landon" <glandon@g...> on Mon, 12 Aug 2002 15:56:36 -0500
Something I wrote here, that validates email addresses..  ASP code is shown
here..
http://www.chizl.com/spammers/

"craig" <cn60@m...> wrote in message news:203720@a..._databases...
>
> Hello,
>
>     below is code for a form to write to an access 2000 database.
> Everything works fine.  But two questions came up that i can not answer.
> 1) how do i prevent duplicate emails from being entered? 2) how do i
> validate the emails being entered?  This is my first attempt at this and i
> am struggling to find an answer. i have read a few articles, but at this
> point they are a little over my head. if you could point me to an article
> that is easy to understand at my level, i would appreciate it. or any
> insight at all.
>
> thanks,
> craig
>
>
>
>
>  <%
> IF request.form ("Message")="True" THEN
> strTB1=request.form("FirstTextBox")
> strTB2=request.form("SecondTextBox")
> strTB3=request.form("EMail")
>
>
> 'Opening the DataBase Object
> set objConn = server.createobject("ADODB.Connection")
>     objConn.Open "DSN=info"
> set cm = Server.CreateObject("ADODB.Command")
> cm.ActiveConnection = objConn
>
> cm.CommandText ="INSERT INTO SampleDb(TB1,TB2,TB3) VALUES (?,?,?)"
>
>
> 'First Text Box Parameter Statement
> set objparam=cm.createparameter(, 200, , 255, strTB1)
> cm.parameters.append objparam
>
> 'Second Text Box Parameter Statement
> set objparam=cm.createparameter(, 200, , 255, strTB2)
> cm.parameters.append objparam
>
> 'Third Text Box Value Parameter Statement
> set objparam=cm.createparameter(, 200, , 255, strTB3)
> cm.parameters.append objparam
>
>
>
>
>
> cm.execute
> response.write("Thank you!")
> ELSE%>
>
>



  Return to Index