Because variables can differ in scope and can overlap, you need to be aware that sometimes a variety of variables will be available to a ColdFusion application page and some may variables may share the same name.
To ensure ColdFusion evaluates the appropriate variable, reference a variable by prefixing a variable name with its type. The table below describes each variable by its prefix.
| Variable Type | Prefix | Reference Syntax |
|---|---|---|
| Local | Variables. | Variables.VariableName |
| Query | *QueryName. | QueryName.VariableName |
| Form | Form. | Form.VariableName |
| URL | URL. | URL.VariableName |
| Cookie | Cookie. | Cookie.VariableName |
| CGI. | CGI. | CGI.VariableName |
| Application | Application. | Application.VariableName |
* Where QueryName is the NAME attribute that you assigned in the CFQUERY tag. You will learn more about querying a database in the next chapter.
The code below outputs the current value of the ProductName local variable:
<CFOUTPUT>
#Variables.ProductName#
</CFOUTPUT>
The code below outputs the current value of the ProductName form variable:
<CFOUTPUT>
#Form.ProductName#
</CFOUTPUT>
The code below outputs the current value of the ProductName query results:
<CFOUTPUT QUERY="ProductName" DATASOURCE="HRApp">
#ProductName.ProductName#
</CFOUTPUT>
| Note: | Allaire recommends that you prefix any variables other than local when referencing them. |