?
Solved

VALIDATE IF USER EXIST

Posted on 2008-09-29
3
Medium Priority
?
206 Views
Last Modified: 2013-12-16
Hello experts.
I have one insert user page and the cfquery:
<cfquery name="Adduser" datasource="mydb">
   INSERT INTO users (Firstname, Lastname, country, City, email)
  VALUES ('#Form.Firstname#',#Form.Lastname#, '#Form.country#','#Form.City#','#Form.email#')
</cfquery>
I want to check first if there is already a user with the same  email.
If so than redirect to a page userexist.cfm
If not than after inserting the user redirect to userdetailpage.cfml
(i use coldfusion and sql.)
Any help?
0
Comment
Question by:Panos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 800 total points
ID: 22595143
run a SELECT query before your INSERT query to select user with submitted email address - if the SELECT query returns any rows, then a user with that email address already exists = redirect to userexists; otherwise proceed with your INSERT query.

<cfquery name="Checkuser" datasource="mydb">
   SELECT email FROM users WHERE email = <cfqueryparam cfsqltype="cf_sql_varchar" value="#Form.email#">
</cfquery>
<cfif Checkuser.recordcount>
... redirect ....
<cfelse>
... your insert query....
</cfif>
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 1200 total points
ID: 22595164
Check this:
<cfquery name="Checkuser" datasource="mydb">
   SELECT Firstname, Lastname, country, City, email FROM users WHERE email='#Form.email#'
</cfquery>
<cfif Checkuser.RecordCount GT 0 >
<cflocation url="userexist.cfm" >
<cfelse>
<cfquery name="Adduser" datasource="mydb">
   INSERT INTO users (Firstname, Lastname, country, City, email)
  VALUES ('#Form.Firstname#',#Form.Lastname#, '#Form.country#','#Form.City#','#Form.email#')
</cfquery>
<cflocation url="userdetailpage.cfm" >
</cfif>

Open in new window

0
 
LVL 2

Author Closing Comment

by:Panos
ID: 31501132
Thank you both for your help.
regards
Panos
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question