Skip to main content
Inspiring
March 26, 2009
Answered

Passing a simple id via url using a hyperlink problem

  • March 26, 2009
  • 2 replies
  • 585 views
I can't believe I can't figure this one out, I am passing an id via the url variables using a hyper link. It comes back with an error in my linked page saying there is an error in the way I used a function. I don't get it, it's a function I use all the time. Here is my queries that are passing and receiving the id.

indexpage:
<cfquery name="useRec" datasource="#APPLICATION.dataSource#">
SELECT user.Fname AS ViewField1, user.email AS ViewField6, user.Lname AS ViewField3, user.userName AS ViewField4, user.password AS ViewField5, lastLogin, hits, user.ID AS ID
FROM user
</cfquery>

<cfoutput query="useRec">
<a href="page2.cfm?ID=#ID#" class="nav">View user Record</a>
</cfoutput>

PAGE 2

<cfparam name="ID" type="integer" default="#url.ID#">
<cfquery name="useRec" datasource="#APPLICATION.dataSource#">
SELECT user.Fname AS ViewField1, user.email AS ViewField6, user.Mname AS ViewField2, user.Lname AS ViewField3, user.userName AS ViewField4, user.password AS ViewField5, user.admin AS ViewField6 user.lastLogin AS lastLogin, user.hits AS hits, user.ID
FROM user
<cfif isDefined("URL.ID")>
WHERE ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer">
</cfif>
</cfquery>

this is my error:
Error Executing Database Query. [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
The error occurred on line 11.

It is throwing an error on my if statement. I have tried a number of different options and still the same error.

Can anyone see what I might have missed?

Thank you.
    This topic has been closed for replies.
    Correct answer Newsgroup_User
    your table name - USER - is very likely a reserved word in your database.

    try using it in square brackets: [user]

    btw, since you are selecting from only one table, you do not need to
    prefix every column name with table name...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

    2 replies

    Inspiring
    March 26, 2009
    Azadi answered your question. My general suggestion is to start paying closer attention to your error messages. For some reason, you misinterpreted the one you got big time.
    CFmongerAuthor
    Inspiring
    March 26, 2009
    Yes he did. I also found that I missed a comma in my query. It is all fixed now. I had to walk away from it for a couple of hrs to find it.

    Thank you for the help.
    Newsgroup_UserCorrect answer
    Inspiring
    March 26, 2009
    your table name - USER - is very likely a reserved word in your database.

    try using it in square brackets: [user]

    btw, since you are selecting from only one table, you do not need to
    prefix every column name with table name...

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/