Solved

VALIDATE IF USER EXIST

Posted on 2008-09-29
3
197 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
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

914 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

19 Experts available now in Live!

Get 1:1 Help Now