Home | Advertising Info42 USERS CURRENTLY ONLINE   
PowerASP
   Site Search Contact Us Wednesday, May 01, 2024  

  Active InfoActive Info  Display List of Info MembersMemberlist  Search The InfoSearch  HelpHelp
  RegisterRegister  LoginLogin
Classic ASP - Database Issues
 PowerASP Code Help Area : Classic ASP - Database Issues
Subject Info: need code to prevent duplicate data A d d  -  P o s tAdd P o s t
Author
Message << Prev Info | Next Info >>
sandrawg
Newbie
Newbie


Joined: July/29/2005
Location: United States
Online Status: Offline
Info: 1
Added: July/29/2005 at 3:18am | IP Logged Quote sandrawg

I am working with a form where the user enters personal information like name and email address that will go into a database. I am a real ASP newbie, and I need some help. I basically need the form to check the information the user has submitted and make sure it's not already in the database. The fields we want to check are:

email address: email_address
first name: first_name
last name: last_name

If the info is already in the database, there should be a response.write that says something like "sorry, you already registered."

The form action's asp file has the following code:

<%
Dim chkContact, random_number

' begin random function
randomize

' random numbers is the varible that will contain a numeriv value
' between one and nine
random_number=int(rnd*90000)+1
random_number = right(CStr(random_number + 1000000),5)

' write the random number out to the browser
'response.write random_number

If Request.Form("signup") = "Yes" Then
 chkContact = True
Else
 chkContact = False
End If

strSQL = "SELECT * from user_info"

Set r_user_info = Server.CreateObject("ADODB.Recordset")
r_user_info.Open strSQL, strConnect, adOpenStatic, adLockOptimistic, adCmdText
' r_user_info.MoveLast
' iOrderCode = r_user_info.Fields("OrderCode").Value + 1

' response.write "This is a test:"&Trim(Request.Form("pets_name"))

r_user_info.AddNew
r_user_info.Fields("dAdded").Value = Date()
' r_user_info.Fields("OrderCode").Value = iOrderCode
r_user_info.Fields("pet_name").Value = Trim(Request.Form("pets_name"))
r_user_info.Fields("petType").Value = Trim(Request.Form("petType"))
r_user_info.Fields("petTypeOther").Value = Trim(Request.Form("petTypeOther"))
r_user_info.Fields("signup").Value = chkContact
r_user_info.Fields("zip").Value = Trim(Request.Form("zip"))
r_user_info.Fields("state").Value = Trim(Request.Form("state"))
r_user_info.Fields("city").Value = Trim(Request.Form("city"))
r_user_info.Fields("email_address").Value = Trim(Request.Form("email_address"))
r_user_info.Fields("last_name").Value = Trim(Request.Form("last_name"))
r_user_info.Fields("first_name").Value = Trim(Request.Form("first_name"))
r_user_info.Fields("random_number").Value = random_number
r_user_info.Update

r_user_info.Close
set r_user_info = Nothing

Response.Redirect "result.asp?z="&Trim(Request.Form("zip"))&"&fn=" &Trim(Request.Form("first_name"))&"&ln="&Tri m(Request.Form("last_name"))&"&rc="&random_numbe r
%>

Since I am so new at this, I need someone to give me the code and show me where to put it in the above script.

thanks!!

 

 

 

Back to Top View sandrawg's Profile Search for other info by sandrawg
 
firas_TheGeek
Newbie
Newbie
Avatar

Joined: May/27/2006
Location: Oman
Online Status: Offline
Info: 28
Added: May/27/2006 at 8:52am | IP Logged Quote firas_TheGeek

i didnt get the idea about the random number

but to check if the user is already registered look at the following

the code at beging of the page where the form is in:

<%
if request.querystring("msg")<>"" then
response.write request.querystring("msg")
end if

%>

 

The code for the page that will check the fields:

<%
Dim chkContact

If Request.Form("signup") = "Yes" Then
 chkContact = True
Else
 chkContact = False
End If

strSQL = "SELECT * from user_info WHERE email_address='" & request.form("email_address") & "' and first_name='" & request.form("first_name") & "' and last_name='" & request.form("last_name") & "'"

Set r_user_info = Server.CreateObject("ADODB.Recordset")
r_user_info.Open strSQL, strConnect, adOpenStatic, adLockOptimistic, adCmdText
' r_user_info.MoveLast
' iOrderCode = r_user_info.Fields("OrderCode").Value + 1

' response.write "This is a test:"&Trim(Request.Form("pets_name"))

if r_user_info.eof=true then

r_user_info.AddNew
r_user_info.Fields("dAdded").Value = Date()
' r_user_info.Fields("OrderCode").Value = iOrderCode
r_user_info.Fields("pet_name").Value = Trim(Request.Form("pets_name"))
r_user_info.Fields("petType").Value = Trim(Request.Form("petType"))
r_user_info.Fields("petTypeOther").Value = Trim(Request.Form("petTypeOther"))
r_user_info.Fields("signup").Value = chkContact
r_user_info.Fields("zip").Value = Trim(Request.Form("zip"))
r_user_info.Fields("state").Value = Trim(Request.Form("state"))
r_user_info.Fields("city").Value = Trim(Request.Form("city"))
r_user_info.Fields("email_address").Value = Trim(Request.Form("email_address"))
r_user_info.Fields("last_name").Value = Trim(Request.Form("last_name"))
r_user_info.Fields("first_name").Value = Trim(Request.Form("first_name"))
r_user_info.Fields("random_number").Value = random_number
r_user_info.Update

r_user_info.Close
set r_user_info = Nothing

Response.Redirect "result.asp?z="&Trim(Request.Form("zip"))&"&fn=" &Trim(Request.Form("first_name"))&"&ln="&Tri m(Request.Form("last_name"))&"&rc="&random_numbe r

else

response.redirect "[the page where the form is in]?msg=You are already registered please chose another email address"

end if
%>

 

 

what will happen is that the database will open the table, and if he found a record that has the same first and last name and email address then he is registered, so he will be redirected to the page where he filled the form at, with the querystring msg and in the form page when he finds that there is a querystring msg that means the user has came back from the checkpage so he will display the message

but if the email and the first and last name werent in the database then the user is new so he will be registred

 

hope this helps

Best Regards



__________________
Firas S Assaad (TheGeek)
firas489@gmail.com
0096892166434
http://firas-thegeek.blogspot.com
Back to Top View firas_TheGeek's Profile Search for other info by firas_TheGeek Visit firas_TheGeek's Homepage
 

If you wish to make a comment to this info you must first login
If you are not already registered you must first register

  A d d  -  P o s tAdd P o s t
Printable version Printable version

Info Jump
You cannot add new info in this area
You cannot add to info in this area
You cannot delete your info in this area
You cannot edit your info in this area
You cannot create polls in this area
You cannot vote in polls in this area

   Active Server Pages Rule The World
Contact Us  
All artwork, design & content contained in this site are Copyright © 1998 - 2024 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP ASP.NET .aspx .ascx Web HTML Developer Internet Microsoft Web Services Visual Studio .NET CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspprotect.com, www.cjwsoft.com,www.aspclassifieds.com,www.aspphotogallery.com