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

x
?
Solved

I am having a problem with varable undefined error

Posted on 2009-07-08
19
Medium Priority
?
265 Views
Last Modified: 2013-12-20
Hi Folks,

I am having a problem running this script.  The idea is to take specific records and line up each record and its fields for the user to view on the next page.

My problem is I am getting a Variable form.htitle_ is undefined error and its pointing to this line. <cfset hID = Evaluate(hID)>

I hope I have explained this ok.  Please let me know if you need more info.

Thanks!!!

<cfif form.build IS Build KC Report>
 
<cfquery name=deleterecords datasource=#DS#>
Delete from #kcr#
</cfquery>
 
<cfquery name=numrecords datasource=#DS#>
Select count(*) as numRec
From #kch#
Where approver_type = #URL.aid#
</cfquery>
 
<cfoutput query=numrecords>
<cfset recNum = #numRec#>
</cfoutput>
<cfset hCount = 0>
 
<cfloop index=Add from=1 to=#recNum# step=1>
	<cfset hCount= hCount + 1>
	<cfset hID = form.htitle_#hCount#>
	<cfset hID = Evaluate(hID)>
	<cfset rOffice = form.roffice_#hCount#>
	<cfset rOffice = Evaluate(roffice)>
	<cfset rank = form.rank_#hCount#>
	<cfset rank = Evaluate(rank)>
 
<cfquery name=insert_highlights datasource=#DS#>
	Insert into #kcr# (highlight, office, rank)
	Values (#hID#, #roffice#, #rank#)
</cfquery>
 
<cflocation url=view_current_report.cfm?oid=#URL.oid#&aid=#url.aid# addtoken=no>

Open in new window

0
Comment
Question by:Shwapy
  • 8
  • 5
  • 4
  • +1
19 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24806691
you have 2 varibales with the same name
<cfset hID = form.htitle_#hCount#>
        <cfset hID = Evaluate(hID)>
also why don;t you use index
<cfset hID = form.htitle_#Add#>
0
 
LVL 8

Expert Comment

by:MartinCMS
ID: 24806711
look like you're missing the # around the variable on each of the evaluation setting.

<cfset hID = Evaluate(#hID#)>
<cfset rOffice = Evaluate(#roffice#)>
<cfset rank = Evaluate(#rank#)>

0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24806724
good catch it should be
<cfset hID = #Evaluate(hID)#>
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 52

Expert Comment

by:_agx_
ID: 24806735
We need to see the form code, but the error is pretty clear. The field name you are trying to evaluate does not exist.  There are many causes:
1) using the wrong field name
2)  using <form method="get"..> instead of <form method="post"...>
3) trying to evaluate the fields _before they exist
etc..

>   <cfset hID = form.htitle_#hCount#>
>   <cfset hID = Evaluate(hID)>

     You really do not need to use evaluate().  FORM is a structure, so you can just use array notation
     to access the field names:

    <cfloop from="1" to="10" index="counter">
          <cfset currentRank = FORM["rank_"& counter]>
   </cfloop>

There are a few other problems with the code, but we need to see the <form ..> code first.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24806746
> good catch it should be
> <cfset hID = #Evaluate(hID)#>

No. If they absolutely insist on using evaluate the # signs are not needed:

      <cfset hID = Evaluate(hID)>
0
 
LVL 8

Expert Comment

by:MartinCMS
ID: 24806750
Thanks erikTsomik for the correction!
0
 

Author Comment

by:Shwapy
ID: 24806818
Thanks guys I will post the form code...
0
 
LVL 52

Expert Comment

by:_agx_
ID: 24806839
Shwapy,

When you get this problem fixed there are also a number of other problems (and potential problems) in the code you may want to fix:

1. These queries are a _big_ sql injection risk. Always use cfqueryparam for parameters like #URL.aid#. Since you cannot use cfqueryparam for table names, if the #kch# and #kcr# tables are user supplied values  (ie #URL.kch# or #FORM.kch# ) they should be validated first.

<cfquery name=numrecords datasource=#DS#>
Select count(*) as numRec
From #kch#
Where approver_type = #URL.aid#
</cfquery>

<cfquery name=deleterecords datasource=#DS#>
Delete from #kcr#
</cfquery>

2. Do not use a query to determine the record count.  HTML is stateless so the data may change in between the query and the loop.  Store the values in a form field instead.

<cfoutput query=numrecords>
<cfset recNum = #numRec#>
</cfoutput>

3. Use cftransaction around the cfloop so you are not left with incomplete data if an error occurs.

4.  Start using quotes "" around values. It is proper coding and will prevent accidental syntax errors

      Use:
      <cfquery name="deleterecords" datasource="#DS#">

      Not:
      <cfquery name=deleterecords datasource=#DS#>

0
 

Author Comment

by:Shwapy
ID: 24807194
ok, here is the form that calls the above code...

Thanks


<cfquery name =combine datasource=#DS#>
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status=AA4
Order by office
</cfquery>
 
<cfquery name =numRecords datasource=#DS#>
Select count(*) as numRec
From #kch#
Where status=AA4
</cfquery>
 
<cfquery name =get_office datasource=#DS#>
Select * from #kco#
</cfquery>
 
<cfset office_names= ValueList(get_office.office_name)>
<cfset rank_num= 1,2,3,4,5,6,7,8,9,10>
 
<html>
<head>
<cfform action=build_kc.cfm?oid=#URL.oid#&aid=#url.aid#>
 
<table&&>
 
<cfset rCount =0 >
<cfoutput query=combine>
<cfset kid= #kc_highlights_id#>
<cfset rCount=rCount + 1>
<cfif CurrentRow MOD 2 IS 1>
	<cfset class = Blue_TD>
<cfelse>
	<cfset class = White_TD>
</cfif>
<tr>
<td class=#class#><a href=update_kc.cfm?id=#URLEncodedFormat(Trim(kid))#& oid=#URL.oid#&aid=#url.aid#=URL.aid#&at=#approver_type#>#title#</a>
<input type=hidden name=htitle_#rCount# value=#kid# ></td><td class=#class#><select name=rOffice_#rCount# class=KC_office>
	<option value=XO>XO</Option>
				
				
	</option>
</select></td>
 
<td class=#class#><select name=rank_#rCount# class=KC_office>
	<option value=1>1</Option>
				
				
	</option>
	</select></td>
 
</tr>
</cfoutput>

Open in new window

0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24807275
by look at the I can say that how you do not have write the code, there is double and single qoates anywhere. And will not sure that the query will return something anyway.

Even here
cfquery name =combine datasource=#DS#>
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status=AA4
Order by office
</cfquery>

Should be
cfquery name ="combine" datasource=#DS#>
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status=<cfqueryparam cfsql_type="varchar" value="AA4">
Order by office
</cfquery>


and so on and so forth
0
 

Author Comment

by:Shwapy
ID: 24807384
Sorry for some reason when I pasted the code in "Attach Code Snippet" it took out the quotes.......


<cfquery name =combine datasource=#DS#> 
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status=AA4
Order by office
</cfquery>
 
<cfquery name =numRecords datasource=#DS#> 
Select count(*) as numRec 
From #kch# 
Where status=AA4
</cfquery>
 
<cfquery name =get_office datasource=#DS#> 
Select * from #kco#
</cfquery>
 
<cfset office_names= ValueList(get_office.office_name)>
<cfset rank_num= 1,2,3,4,5,6,7,8,9,10> 
 
<html>
<head>
<cfform action=build_kc.cfm?oid=#URL.oid#&aid=#url.aid#> 
 
<table&&>
 
<cfset rCount =0 > 
<cfoutput query=combine> 
<cfset kid= #kc_highlights_id#>
<cfset rCount=rCount + 1>
<cfif CurrentRow MOD 2 IS 1>
     <cfset class = Blue_TD> 
<cfelse>
     <cfset class = White_TD> 
</cfif>
<tr>
<td class=#class#><a href=update_kc.cfm?id=#URLEncodedFormat(Trim(kid))#& oid=#URL.oid#&aid=#url.aid#=URL.aid#&at=#approver_type#>#title#</a>
<input type=hidden name=htitle_#rCount# value=#kid# ></td><td class=#class#><select name=rOffice_#rCount# class=KC_office> 
     <option value=XO>XO</Option>
                 
                 
     </option>
</select></td>
 
<td class=#class#><select name=rank_#rCount# class=KC_office> 
     <option value=1>1</Option>
                 
                 
     </option>
     </select></td>
 
</tr>
</cfoutput>
0
 

Author Comment

by:Shwapy
ID: 24807406
<cfquery name =combine datasource=#DS#>
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status=AA4
Order by office
</cfquery>

<cfquery name =numRecords datasource=#DS#>
Select count(*) as numRec
From #kch#
Where status=AA4
</cfquery>

<cfquery name =get_office datasource=#DS#>
Select * from #kco#
</cfquery>

<cfset office_names= ValueList(get_office.office_name)>
<cfset rank_num= 1,2,3,4,5,6,7,8,9,10>

<html>
<head>
<cfform action=build_kc.cfm?oid=#URL.oid#&aid=#url.aid#>

<table&&>

<cfset rCount =0 >
<cfoutput query=combine>
<cfset kid= #kc_highlights_id#>
<cfset rCount=rCount + 1>
<cfif CurrentRow MOD 2 IS 1>
      <cfset class = Blue_TD>
<cfelse>
      <cfset class = White_TD>
</cfif>
<tr>
<td class=#class#><a href=update_kc.cfm?id=#URLEncodedFormat(Trim(kid))#& oid=#URL.oid#&aid=#url.aid#=URL.aid#&at=#approver_type#>#title#</a>
<input type=hidden name=htitle_#rCount# value=#kid# ></td><td class=#class#><select name=rOffice_#rCount# class=KC_office>
      <option value=XO>XO</Option>
                        
                        
      </option>
</select></td>

<td class=#class#><select name=rank_#rCount# class=KC_office>
      <option value=1>1</Option>
                        
                        
      </option>
      </select></td>

</tr>
</cfoutput>
0
 

Author Comment

by:Shwapy
ID: 24807453

sorry guys,

Lets try this again



<cfquery name ="combine" datasource=#DS#">
Select kc_highlights_id, title, office, poc_1, approver_type
From #kch#
Where status='AA4'
Order by office
</cfquery>

<cfquery name ="numRecords" datasource="#DS#">
Select count(*) as "numRec"
From "#kch#"
Where status='AA4'
</cfquery>

<cfquery name ="get_office" datasource="#DS#">
Select * from #kco#
</cfquery>

<cfset office_names= ValueList(get_office.office_name)>
<cfset rank_num= "1,2,3,4,5,6,7,8,9,10">

<html>
<head>
<cfform action="build_kc.cfm?oid=#URL.oid#&aid=#url.aid#">

<table&&>

<cfset rCount =0 >
<cfoutput query="combine">
<cfset kid= #kc_highlights_id#>
<cfset rCount=rCount + 1>
<cfif CurrentRow MOD 2 IS 1>
      <cfset class = "Blue_TD">
<cfelse>
      <cfset class = "White_TD">
</cfif>
<tr>
<td class="#class#"><a href="update_kc.cfm?id=#URLEncodedFormat(Trim

(kid))#&

oid=#URL.oid#&aid=#url.aid#=URL.aid#&at=#approver_type#">#title#</a>
<input type="hidden" name="htitle_#rCount#" value="#kid#" ></td><td

class="#class#"><select name="rOffice_#rCount#" class="KC_office">
      <option value="XO">XO</Option>
      "      "      "      "
      "      "      "      "
      </option>
</select></td>

<td class="#class#"><select name="rank_#rCount#" class="KC_office">
      <option value="1">1</Option>
      "      "      "      "
      "      "      "      "
      </option>
      </select></td>

</tr>
</cfoutput>
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24807474
try givving the diff name to
<cfset hID = Evaluate(hID)>

amy be this
<cfset hID2 = Evaluate(hID)>
0
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 24807666
Shwapy,

You could greatly simplify the code by just using the cfquery #CurrentRow# variable to generate the field names.  Also, by eliminating Evaluate() which is not needed.

FORM:
<cfoutput query="combine">

   <a href="update_kc.cfm?id=#URLEncodedFormat(Trim(kc_highlights_id))#&oid=#URL.oid#&aid=#url.aid#=URL.aid#&at=#approver_type#">#title#</a>
   <input type="hidden" name="htitle_#currentRow#" value="#kc_highlights_id#" >
   <select name="rOffice_#CurrentRow#" class="KC_office">
      ...options ...
   </select>

   <select name="rank_#CurrentRow#" class="KC_office">
      ...options ...
   </select>

</cfoutput>
<!--- store the total fields in a hidden field --->
<cfoutput>
  <input type="hidden" name="totalFields" value=#combine.recordCount#">
</cfoutput>


Then use the hidden field to do your loop on the action page.  No need for Evaluate(..) at all. Just use array notation to grab the values.


ACTION PAGE:
<cfparam name="form.totalFields" default="0">

<cfloop from="1" index="#form.totalFields#" index="x">
        <cfset hID = form["htitle_"& x]>
        <cfset rOffice = form["roffice_"& x]>
        <cfset Rank = form["rank_"& x]>
        <!--- use CFQUERYPARAM here --->
      <cfquery name=insert_highlights datasource=#DS#>
           Insert into #kcr# (highlight, office, rank)
           Values ( #hID# , #roffice#, #rank# )
      </cfquery>
</cfloop>
 
0
 

Author Comment

by:Shwapy
ID: 24808019
Thanks aqx and to everyone else.  I will give this a try and let you know how it works out.
0
 
LVL 19

Expert Comment

by:erikTsomik
ID: 24808064
and also please work on your programming technics, make the code is readable and maintenable as possible
0
 

Author Comment

by:Shwapy
ID: 24808192
Will do erikTsomik thank you for all of your advise.  I'm learning everyday.

0
 

Author Closing Comment

by:Shwapy
ID: 31601255
Thanks for your help!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
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…

876 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