Riot Goes Woof
Riot Goes Woof

Reputation: 3514

ColdFusion syntax error when using data from one query in another query

I have the following code below, which is supposed to get student information based on their parking permit number:

<cfparam name="Permit" default="">

<cfquery name="q_sample" datasource="cars_live">
  SELECT * FROM veh_rec WHERE UPPER(DECAL) LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="#trim(urldecode(UCase(Permit)))#">
</cfquery>

<cfif q_sample.recordcount eq 0> 
No Results found for <cfoutput>"#Permit#"</cfoutput> 
</cfif>

<cfquery name="s_sample" datasource="cars_live">
  SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>
</cfquery>

<cfoutput query="s_sample">
  <p>Name: #FULLNAME#<p>
</cfoutput>

<cfoutput query="q_sample" >
  <p>License Plate Number: #license# <br><br> Permit ID Number: #decal#<br><br> Student ID Number: #ID# <br><br> Academic years: #ACADYR#<br><br></p>
</cfoutput>

The license plate, permit ID number, and such all work fine, but when I try to use the #q_sample.ID# tag, I get a syntax error. However when I look at the error in chrome's console window, I can see that it is getting the correct ID based on the permit number. Not sure why this is happening. Does anyone see what I'm doing wrong?

Thank you!

as requested:

Error:

The web site you are accessing has experienced an unexpected error.
Please contact the website administrator. 

The following information is meant for the website developer for debugging purposes.
Error Occurred While Processing Request
Error Executing Database Query.

A syntax error has occurred.

The error occurred in /d2/www/vhosts/joeyP.cfm: line 11
9 : 10 : <cfquery name="s_sample" datasource="cars_live">11 :   SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>12 : </cfquery>13 : 

VENDORERRORCODE   -201

SQLSTATE      42000

SQL    SELECT FULLNAME FROM id_rec WHERE ID = 371043>

DATASOURCE    cars_live

Resources:

Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.

Browser     Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36

Remote Address      10.200.168.210

Referrer    http://{redacted}/tests/yup.html

Date/Time   10-Jun-13 09:17 AM

Stack Trace
at cfjoeyP2ecfm876470777.runPage(/d2/www/vhosts/joeyP.cfm:11) at cfjoeyP2ecfm876470777.runPage(/d2/www/vhosts/joeyP.cfm:11) 

number I was testing was 371043

Upvotes: 1

Views: 797

Answers (1)

Matt Busche
Matt Busche

Reputation: 14333

You have an extraneious > at the end of this query. If you take that out it should fix your issue.

<cfquery name="s_sample" datasource="cars_live">
SELECT FULLNAME FROM id_rec WHERE ID = #q_sample.ID#>
</cfquery>

Upvotes: 4

Related Questions