Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Error with cfdiv and database query

Guest
May 10, 2011 May 10, 2011

I meet a weird error,

this is my first page.

<cfform>

<table>

<tr>

<th colspan="2">

<h2>Find a location</h2>

</th>

</tr>

<tr>

<td>

Location:<br />

<cfset State = createObject("component", "location").getState()>

<cfselect name="StateID"

  query="State"

  required="yes"

  message="Please select a location."

  display="State"

  value="State_ID"

  queryposition="below">

<option value="">Select State</option>

</cfselect>

</td>

<td>

Area:<br />

<cfselect name="LocationID"

  bind="cfc:location.getAreas({StateID})"

  display="Area"

  value="Location_ID">

 

</cfselect>

</td>

</tr>

<tr>

<td colspan="2" abbr="center">

<input type="submit" value="Search">

</td>

</tr>

</table>

<table>

<tr>

<td>

<cfdiv bind="url:location_result2.cfm?StateID={StateID@change}&LocationID={LocationID@change}">

</td>

</tr>

</table>

</cfform>

-----------------------------------------------------------------------------------------------------------------

and this is my cfc file

<cfcomponent>

<cfset ds = "Reservation">

<!--- Get array of ratings types --->

<cffunction name="getState"

access="remote"

returntype="Query"

hint="Get State for Ajax SELECT">

<!--- Define variables --->

<cfset var ta="">

<!--- Get data --->

<cfquery name="ta" datasource="#ds#">

SELECT State_ID, Trim(State) AS State

FROM State

ORDER BY State

</cfquery>

<!--- And return it --->

<cfreturn ta>

</cffunction>

<!--- Get films by rating --->

<cffunction name="getAreas"

access="remote"

returnType="Query"

hint="Get area by rating for AJAX select">

<cfargument name="LocationID2"

type="numeric"

required="true">

<!--- Define variable --->

<cfset var ta="">

<!--- Get data --->

<cfquery name="ta" datasource="#ds#">

SELECT Location_ID, State_ID, Trim(Area) AS Area

FROM Location

WHERE State_ID  = (#ARGUMENTS.LocationID2#)

ORDER BY State_ID

</cfquery>

<cfreturn ta>

</cffunction>

<cffunction name="sendFeatures"

returntype="Query"

access="public">

<cfargument name="StateID" type="any"  default="">

<cfargument name="LocationID" type="any"  default="">

<cfset var data ="">

<cfquery datasource="#ds#" name="data">

SELECT s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID

FROM State s, Location l, Restaurants r

WHERE 0=0

AND r.Location_ID = l.Location_ID

AND l.State_ID = s.State_ID

<cfif (#ARGUMENTS.LocationID#) IS (#ARGUMENTS.StateID#)>

AND l.State_ID = (#ARGUMENTS.LocationID#)

<cfelse>

AND l.Location_ID = (#ARGUMENTS.LocationID#)

</cfif>

</cfquery>

<cfdump var="#arguments#">

<cfreturn data>

</cffunction>

</cfcomponent>

-------------------------------------------------------------------------------------------------------

i keep get this error.

Error Executing Database Query.

The error occurred in E:\wamp\www\Test\location2.cfc: line 61
Called from E:\wamp\www\Test\location_result2.cfm: line 11
Called from E:\wamp\www\Test\location2.cfc: line 61
Called from E:\wamp\www\Test\location_result2.cfm: line 11
59 :           AND l.State_ID = (#ARGUMENTS.LocationID#)
60 :           <cfelse>
61 :                AND l.Location_ID = (#ARGUMENTS.LocationID#)
62 :           </cfif>
63 :           </cfquery>

but when i continue click and the select, at the end i can get the result which i want.

Can please give me some tips to avoid this error ?

457
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 10, 2011 May 10, 2011
LATEST

First, what are the values of the arguments that are being passed in?  Based on your query, it looks like you are looking for integer values.  However, you are defaulting the arguments to '';  So if both the locationId and StateId are not passed in, your query will surely fail because it would have And l.State_id =

So first, I would default your Id's to 0 instead of ll; Then I would write the query like

<cfquery datasource="#ds#" name="data">

SELECT      s.State_ID, s.State, l.Location_ID, l.Area, l.State_ID, r.Name, r.Location_ID

FROM        State s, Location l, Restaurants r

WHERE  r.Location_ID = l.Location_ID

     AND  l.State_ID = s.State_ID

<cfif ARGUMENTS.LocationID EQ ARGUMENTS.StateID AND Arguments.LocationID NEQ 0>

AND l.State_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocationId#">

<cfelse>

AND l.Location_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.LocationId#">

</cfif>

</cfquery>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources