Solved

VALIDATE IF USER EXIST

Posted on 2008-09-29
3
202 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 200 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 300 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

Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

615 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