User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 332,691 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,419 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 616 | Replies: 2 | Solved
Reply
Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

<cfquery> Undefined

  #1  
Mar 27th, 2008
I need some help with <cfquery>, I want to authenticate an add form so the user doesn't enter the same value twice or more so I used recordcount like this

  1. <cfquery name="cool.recordcount" datasource="#Request.proto#">
  2. <cfif cool EQ 0>
  3. INSERT INTO proton(
  4. name,
  5. moon
  6. )
  7. VALUES(
  8. '#Trim(Form.name)#',
  9. '#Trim(Form.moon)#',
  10. )
  11. <cfif cool EQ 0>
  12. <cfelse>
  13. THIS RECORD ALREADY EXIST
  14. <cfinclude template="adduser.cfm">
  15. </cfif>
  16. </cfquery>

but it throws an error like Variable COOL is undefined. I am also using anplication.cfm Application.cfm also in my form, is their anything you can see I am doing wrong or do I have to define the query name cool, it is already defined in the cfquery?
Last edited by peter_budo : Mar 30th, 2008 at 5:35 am. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2008
Posts: 32
Reputation: cmhampton is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 3
cmhampton cmhampton is offline Offline
Light Poster

Re: <cfquery> Undefined

  #2  
Mar 28th, 2008
First of all, please don't name your query cool.recordCount. RecordCount is a property of the query object. Name it something like qryCool.

Secondly, you're missing a </cfif> tag. You have two cfif statements, but only one closing.

Do you already have code that determines if this is a duplicate record? What is the 'cool' variable for? If you already check, try this code and let me know:

  1. <cfif cool EQ 0>
  2. <cfquery name="qryCool" datasource="#Request.proto#">
  3. INSERT INTO proton(
  4. name,
  5. moon
  6. )
  7. VALUES(
  8. '#Trim(Form.name)#',
  9. '#Trim(Form.moon)#'
  10. )
  11. </cfquery>
  12. <cfelse>
  13. This Record Already Exists
  14. <cfinclude template="adduser.cfm">
  15. </cfif>

Change the adduser.cfm to include it's own <cfquery> tag.

Alternately, you can do it all in SQL if you haven't determined whether this is a duplicate record or not.

  1.  
  2. <cfquery name="qryCool" datasource="#Request.proto#">
  3. IF NOT EXISTS
  4. (
  5. SELECT
  6. name,
  7. moon
  8. FROM
  9. proton
  10. WHERE
  11. name = '#Trim(Form.name)#'
  12. AND moon = '#Trim(Form.moon)#'
  13. )
  14. BEGIN
  15. INSERT INTO proton(
  16. name,
  17. moon
  18. )
  19. VALUES(
  20. '#Trim(Form.name)#',
  21. '#Trim(Form.moon)#'
  22. )
  23.  
  24. SELECT SCOPE_IDENTITY() AS RecordID
  25.  
  26. END
  27.  
  28. ELSE
  29. SELECT NULL AS RecordID
  30. </cfquery>
  31.  
  32. <cfif qryCool.RecordID EQ "">
  33. This Record Already Exists
  34. <cfelse>
  35. <!--- Do something here --->
  36. </cfif>
Reply With Quote  
Join Date: Feb 2008
Posts: 16
Reputation: zoid777 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
zoid777 zoid777 is offline Offline
Newbie Poster

Re: <cfquery> Undefined

  #3  
Mar 29th, 2008
Thanks cmhampton the Direct SQL version worked, I just modified the cfif at the buttom and it works.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 5:03 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC