Solved

VALIDATE IF USER EXIST

Posted on 2008-09-29
3
196 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
3 Comments
 
LVL 27

Assisted Solution

by:azadisaryev
azadisaryev earned 200 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you both for your help.
regards
Panos
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now