Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

VALIDATE IF USER EXIST

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
Panos
Asked:
Panos
2 Solutions
 
azadisaryevCommented:
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
 
ZvonkoSystems architectCommented:
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
 
PanosAuthor Commented:
Thank you both for your help.
regards
Panos
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now