[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Coldfusion CS3 convert ASP page to coldfusion

I am converting a asp to coldfusion.  Here is the asp.

Dim tablename, date_view
      date_view = request.querystring("date_view")
      tablename = request.querystring("tablename")

when I try

<cfset date_view = request.date_view>
<cfset tablename = request.tablename>

I get the error

Element TABLENAME is undefined in REQUEST.
I thought cfset is the equal of Dim so why is tablename undefined?

Any help is greatly appreciated.
0
JohnMac328
Asked:
JohnMac328
  • 15
  • 11
  • 4
  • +1
1 Solution
 
SidFishesCommented:
you are misunderstanding cfset. It's true that it can declare a variable like Dim but it also set the value

so in the case of
<cfset tablename = request.tablename>

you are setting it from the request scope however the error is telling you that it does not exist in the request scope.

HOw are you setting the value of tablename?


0
 
JohnMac328Author Commented:
Hi again

It is referencing the table in the db.  Here is the sql
SQL5 = "SELECT * FROM " & tablename & " ORDER BY ID desc;"

and then with
if tablename="table in db" then response.write...etc
0
 
SidFishesCommented:
that won't work in cf in that manner. (and afaik, you'd need to set the variable tablename in ASP as well)

You first need to set the variable tablename to create your query

<cfset aVariableCalledTableName = "ProductTable">


<cfquery name="getTable" datasource="myDSN">
select * from #aVariableCalledTableName# orderby id desc
</cfquery>

then run your logic

<cfif aVariableCalledTableName  EQ "ProductTable">
the rest or your conditional code...

You need to determine how the variable table name is created in the ASP and then we can convert it to the CF code


Note: this code is fine on one page, but there is no state automagically created to pass the variables so you need to use urls, session variables, request variables or form variables to pass the variable data







0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
JohnMac328Author Commented:
Ok, I have to study this, I am dealing with 13 tables and not sure if this is the way to go.  They are in a list linking to the table in the db.  Here is the first of the 13 tables.

<li><a href="fund_divs.asp?tablename="table in db"></a></li>
0
 
SidFishesCommented:
ok,

then it looks like it's being set by a url value... which is easy to handle


<cfset aVariableCalledTableName = url.ProductTable>


<cfquery name="getTable" datasource="myDSN">
select * from #aVariableCalledTableName# orderby id desc
</cfquery>
0
 
SidFishesCommented:
oops


<cfset TableName = url.tablename>


<cfquery name="getTable" datasource="myDSN">
select * from '#TableName#' orderby id desc  
</cfquery>

You'll need the single quotes in the query
0
 
KerrdoCommented:
Yes,

SidFishes example should work. But I think you need to udnerstand why. The request scope in coldfusion is not the same as the asp request.

request.querysting() in asp is the same as the cf url scope.
where as in coldfusion request is for local variables. (like using Dim in asp i suppose)

So in your example they are actual opposing scopes.

This might help you
http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/Variables7.htm
0
 
JohnMac328Author Commented:
With this cfset

<cfset TableName = url.tablename>

Do I have to have one for each table where I am naming each table?
0
 
SidFishesCommented:
no, you shouldn't from what I can tell as you can only pass one variable at a time via the url

so if you click this link
<a href="fund_divs.asp?tablename="table1">Table1</a>

the url variable (everything after ?) is passed as tablename="table1"

when the query page loads, it reads this variable into the local variable tablename.

<cfset TableName = url.tablename>

it might help to change the local variable to vTablename to differentiate between the url variable and the local

<cfset vTableName = url.tablename>

I do this with all local variables as it helps debugging.

once this local variable is set you can use it in any instance on that page, in this case in the cfquery

<cfquery name="getTableData" datasource="myDSN">
select * from '#vTableName#' orderby id desc  
</cfquery>

<cfoutput>
The Data From #vTableName# is:<br>
<cfloop query="getTableData">
#getTableData.Field1#<br>
#getTableData.Field2#<br>
#getTableData.Field3#<br>
</cfloop>
</cfoutput>

where field1 2 and 3 are actually field names in the table
0
 
JohnMac328Author Commented:
Element TABLENAME is undefined in URL is what I still get
0
 
SidFishesCommented:
You can't load the page without clicking on the url

(and asp needs to be changed to cfm)
<a href="fund_divs.CFM?tablename="table1">Table1</a>

this is  because url.tablename will not exist when cf is trying to parse the values on page load

you can add

<cfparam name="url.tablename" default=""> to ensure the variable exists on page load

you could also set up and actual default

<cfparam name="url.tablename" default="table1">

0
 
JohnMac328Author Commented:
Getting closer, now I get

Error Executing Database Query.  
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error in query. Incomplete query clause.  

It is bombing on this query, I tried with and without the single quotes and still same error message.

select * from '#vTableName#' orderby id desc  
0
 
ZvonkoSystems architectCommented:
No ' needed.
Check this:

select * from #vTableName# orderby id desc  

0
 
JohnMac328Author Commented:
Like I stated before, I tried with and without the single quotes and it still bombs with the same error message.
0
 
KerrdoCommented:
what database are you using?

try this

select * from [#vTableName#] order by id desc
0
 
SidFishesCommented:
quite likely you don't have the query surrounded by <cfoutput>


<cfoutput>
<cfquery name="getTableData" datasource="myDSN">
select * from '#vTableName#' orderby id desc  
</cfquery>
</cfoutput>

with a few exceptions, if a cf variable is not inside a cf tag, you need to enclose it in cfoutput

0
 
SidFishesCommented:
(and you don't need the single quotes...that was my error...it's a table name not a parameter)
0
 
KerrdoCommented:
SidFishes:

You do not need cfoutput tags on a query.
0
 
SidFishesCommented:
sigh... yes of course , you are right...


(note to self - don't answer q's right after getting back from the dentist)
0
 
SidFishesCommented:
now that i have the other half of my brain unfreezing...

order by is 2 words

select * from #vTableName# order by id desc  

0
 
KerrdoCommented:
Yes, but if the table name is a reserved word, like user you sill need to escape it somehow.
the syntax will depend on the db. but I am assuming MSSQL since the site was in asp. the syntax for this should be the same as Access, also a probability for an ASP site.

MSSQL : select * from [union]
MySQL : select * from 'union'
not
select * from union
0
 
SidFishesCommented:
tables names using reserved words????

that never happens!

(right?)

;)
0
 
JohnMac328Author Commented:
I appreciate all the help.  Here is the block of code I am using and here is the latest error msg.

Syntax error in query. Incomplete query clause.  and highlights this line
<cfquery datasource="fund_divs" name="getTableData">



<cfparam name="url.tablename" default="">
<cfset vTableName = url.tablename>



<cfquery datasource="fund_divs" name="getTableData">
            select * from 'vTableName' order by id desc  
</cfquery>
0
 
SidFishesCommented:
close but you need ##'s around your variable (and no single quotes)

<cfquery datasource="fund_divs" name="getTableData">
            select * from #vTableName# order by id desc  
</cfquery>

without them , the query is trying to find a literal table name of vTableName

0
 
JohnMac328Author Commented:
But that takes me back to the original syntax error of

Syntax error in FROM clause

which is this line

select * from #vTableName# order by id desc
0
 
SidFishesCommented:
please comment out the cfquery and tell us what you get when you run this


<cfparam name="url.tablename" default="">
<cfset vTableName = url.tablename>

<cfoutput>#vtableName#</cfoutput>

<!---
<cfquery datasource="fund_divs" name="getTableData">
            select * from #vTableName# order by id desc  
</cfquery>
--->
0
 
JohnMac328Author Commented:
It can't find getTableData which makes sense of course since it is commented out

Attribute validation error for tag cfloop.  
The value of the attribute query, which is currently getTableData, is invalid.  
 
The error occurred in C:\Inetpub\wwwroot\DEv_ColdFusion\institute\fund_divs.cfm: line 56
 
54 : <cfoutput>
55 : The Data From #vTableName# is:<br>
56 : <cfloop query="getTableData">
57 : #getTableData#<br>
58 :
 
0
 
SidFishesCommented:
please comment out the whole bit, except for

<cfparam name="url.tablename" default="">
<cfset vTableName = url.tablename>

<cfoutput>#vtableName#</cfoutput>

we need to find out the value of vTablename
0
 
JohnMac328Author Commented:
I put it in a table with borders showing to find it, it's an empty table.  It doesn't display anything for the value #vtableName#
0
 
SidFishesCommented:
then that's why the cfquery error is occurring, you're not passing the url variable

as I said above, "You can't load the page without clicking on the url"

when you added <cfparam name="url.tablename" default="">
all it did was prevent the error "Element TABLENAME is undefined in URL"

it does not provide data which the query can use. It is a variable without a value so your query is in fact

select * from order by id desc  

which is why the error

if you want to set up a default for testing ie: you don't want to create the variable from the url link

<cfparam name="url.tablename" default="table1">
 this bit creates the variable and populates it with a default value (whatever the tablename you want to use when testing) If there IS a value for url.tablename when the form is loaded (ie: you're calling it from the link) then the default value is ignored


0
 
JohnMac328Author Commented:
Ok thanks for all your help, I will take it from here.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 15
  • 11
  • 4
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now