MySql Error 'Unknown Column' from PHP variable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry in Honolulu

    #1

    MySql Error 'Unknown Column' from PHP variable

    I'm getting an error message that makes no sense to me. I have a table with a
    field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
    php variable holding a specific key number.

    The relevant code is -
    $_testkey = 'LAL10102';
    $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_tes tkey`";
    $result=mysql_q uery($sql,$db_c onn);

    echoing the $sql gives -
    SELECT * FROM `pro_keys` WHERE `keynum`=`LAL10 102`

    But I get the following error -

    MySQL error #1054 - Unknown column 'LAL10102' in 'where clause'

    ?????????

    Thanks for any ideas,
    Larry L
  • Michael Fesser

    #2
    Re: MySql Error 'Unknown Column' from PHP variable

    ..oO(Larry in Honolulu)
    >I'm getting an error message that makes no sense to me. I have a table with a
    >field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
    >php variable holding a specific key number.
    >
    >The relevant code is -
    $_testkey = 'LAL10102';
    $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_tes tkey`";
    $result=mysql_q uery($sql,$db_c onn);
    Strings in an SQL query have to be quoted (and drop the backticks):

    $sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";

    Micha

    Comment

    • naixn

      #3
      Re: MySql Error 'Unknown Column' from PHP variable

      Michael Fesser wrote :
      .oO(Larry in Honolulu)
      >
      >I'm getting an error message that makes no sense to me. I have a table with a
      >field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
      >php variable holding a specific key number.
      >>
      >The relevant code is -
      > $_testkey = 'LAL10102';
      > $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_tes tkey`";
      > $result=mysql_q uery($sql,$db_c onn);
      >
      Strings in an SQL query have to be quoted (and drop the backticks):
      >
      $sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";
      >
      Micha
      You have to remind that `` are used to define MySQL fields, databases, or
      tables, not values ;)

      --
      Naixn

      Comment

      • Larry in Honolulu

        #4
        Re: MySql Error 'Unknown Column' from PHP variable

        In article <fksjn21rkcqrt7 ndg1cot1lg4jk76 f5r7t@4ax.com>, Michael Fesser <netizen@gmx.de wrote:
        >..oO(Larry in Honolulu)
        >
        >>I'm getting an error message that makes no sense to me. I have a table with a
        >>field named 'testkey' for a list of "keys" in the form of ABC10102. I have a
        >>php variable holding a specific key number.
        >>
        >>The relevant code is -
        > $_testkey = 'LAL10102';
        > $sql = "SELECT * FROM `pro_keys` WHERE `keynum`=`$_tes tkey`";
        > $result=mysql_q uery($sql,$db_c onn);
        >
        >Strings in an SQL query have to be quoted (and drop the backticks):
        >
        >$sql = "SELECT * FROM pro_keys WHERE keynum = '$_testkey'";
        >
        >Micha
        Thanks Michael,

        I've been away from MySql for a while and forgot that. Oddly I have another
        query on the same page (different fields and different variable) that uses the
        same syntax, though with no backtics and no quotes of any kind that works just
        fine.

        Larry L

        Comment

        • Larry in Honolulu

          #5
          Re: MySql Error 'Unknown Column' from PHP variable

          In article <457a05fa$0$183 01$79c14f64@nan-newsreader-06.noos.net>, naixn <naixn@won-fma.comwrote:
          >
          >You have to remind that `` are used to define MySQL fields, databases, or
          >tables, not values ;)
          >
          I actually never knew that. I just have seen them used in many places, and
          never had seen any documentation describing where they were appropriate.

          Thanks much for my education.

          Larry L

          Comment

          • Michael Fesser

            #6
            Re: MySql Error 'Unknown Column' from PHP variable

            ..oO(naixn)
            >You have to remind that `` are used to define MySQL fields, databases, or
            >tables, not values ;)
            You don't have to use them.

            Micha

            Comment

            Working...