Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable is undefined error: first time coldfusion user

Status
Not open for further replies.

shaunacg

Programmer
Aug 1, 2003
71
GB
Hi,

I don't know anything about coldfusion, but have to fix an error that says newtradeid is undefined and points to the code below:
<cfoutput>
<cfif newtradeid neq ''>
<table cellspacing=&quot;0&quot; width=&quot;500&quot;><tr><td align=&quot;right&quot; class=&quot;text&quot;>Click<a href=&quot;JavaScript:newPopUp('../tradedetails.cfm?tradeid=#newtradeid#')&quot; class=&quot;newtext&quot;> here </a>to view trade Profile</td></tr></table>
</cfif>
</cfoutput>

it looks like the variable is defined to me in the code above it which says:

<cfquery name=&quot;qgetcars&quot; datasource=&quot;Car2BuyNI&quot;>
select *
from carstosell, carmake
where carstosell.CarMakeID = carmake.carmakeid
AND carstosell.CarToSellID = #url.id#
</cfquery>

<cfoutput query=&quot;qgetcars&quot;>
<cfset newtradeid = #tradeid#>
</cfoutput>

I have tested the sql query alone against the database and it is fine. Do you see something wrong? Thanks for advice.

scg
 
Are you getting any results from the query? If not, that's the source of your problem, the query is not returning a value to set as &quot;newtradeid&quot;. You may want to try replacing <cfif newtradeid neq ''> with <cfif IsDefined(&quot;newtradeid&quot;)>. That should eliminate your error, however nothing between your <cfif></cfif> tags will execute if the variable newtradeid is not defined.

Hope This Helps!

Ecobb
- I hate computers!
 
Hi,

Thank you for that I put that in and the error doesn't come up anymore, the problem is nothing comes up. I checked the SQL query on the database and it works fine and every row has a value for tradeid. Why would nothing at all come up? Even the tables below all that code don't appear. Have you seen this before?

scg
 
Does this happen every time you try to run this page, regardless of what #url.id# you pass to it? Or does it only happen every time you pass this same #url.id#?

Hope This Helps!

Ecobb
- I hate computers!
 
It doesn't happen every time, about half and half. But the values in url.id have a corresponding cartosellid in the database for all of them. I don't see any difference between them to make some show and others not.
 
I'd have to guess (since you don't give any other details about your databases) that the problem is in the join.

What you've written is a simple (or Inner) join... which means that it omits rows that don't meet all the criteria of the join. With your where clause of:
Code:
  where carstosell.CarMakeID = carmake.carmakeid
if there isn't a matching carmakeid in the table carmake for the carmakeid found in the table carstosell, the row isn't returned even though there may be a match for the CarToSellID.

Perhaps you want to do an Outer join instead?


-Carl
 
This is just a wild shot in the dark, but try replacing this line:

<a href=&quot;JavaScript:newPopUp('../tradedetails.cfm?tradeid=#newtradeid#')&quot; class=&quot;newtext&quot;> here </a>

With this line:

<a href=&quot;JavaScript:newPopUp('../tradedetails.cfm?tradeid=
<CFOUTPUT>#newtradeid#</CFOUTPUT>')&quot; class=&quot;newtext&quot;> here </a>

I didn't see any CFOUTPUT tages around that variable, (I
might have missed them) but Javascript will only get the
text #variablename# unless you enclose it in <cfoutput>,
just like any other CF code.

Hope that helps,

MG
 
They're surrounding the entire CFIF block, MG... if you look again.



-Carl
 
Hi,

You're right my query wasn't returning values. There were some wrong values in CarMakeID in the database. Thanks for your help.

Shauna
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top