Invalid column name?!

Discussion in 'Programming' started by seofighter, Jul 16, 2010.

  1. #1
    Hi,,
    I'm passing a variable over a URL. The value is user01.

    The problem is that an error message occurs stating that there is an incorrect column name?! Here is the code below and the error message:

    <cfquery name="userQuery" datasource="xxxxx" username="xxxxx" password="xxxxx">
    SELECT admin FROM users WHERE username="#url.promo#"
    </cfquery>

    It comes up with the following error:

    [Macromedia][SQLServer JDBC Driver][SQLServer]Invalid column name 'user01'.

    Please help.

    Many thanks in advance,
     
    seofighter, Jul 16, 2010 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    To answer the question, most drivers require single (not double) quotes
    ie WHERE username= '#url.promo#'

    But the proper way is not use quotes at all. Instead use cfqueryparam. It helps performance and w/sql injection.

    
        <!--- The cfsqltype should match you db column data type ...--->
         ie WHERE username= <cfqueryparam value="#url.promo#" cfsqltype="cf_sql_varchar">
    
    Code (markup):
     
    Last edited: Jul 16, 2010
    cfStarlight, Jul 16, 2010 IP