SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: unknown column

  1. #1
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    unknown column

    Hello all!

    Can someone help me figure this out, I am running a query and getting the error
    #1054 - Unknown column '42' in 'where clause'

    42 is not the column but the id, here is the query I am running, I checked it many times for errors and can't find what it is!

    Code:
    UPDATE jml_fl_users SET `street`=`535 E 18th St`, `town`=`Flatbush - Ditmas Park`, `city`=`Kings`, `state`=`New York`, `country`=`United States`, `zipcode`=`11226`, `coordinates`=`40.63763458315378,-73.96082556740572`, `phone`=`4657345908`, `website`=`http://www.someurl.com`, `favoritebook`=`some book`, `aboutme`=`some details about me`, `birthdate`=`05-16-2012` WHERE `id` = `42`
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    yet another developer pwned by mysql's evil `backticks`

    backticks are used to delimit identifiers, i.e. column and table names

    everything in red below is regarded as a column name --
    Code:
    UPDATE jml_fl_users 
       SET `street` = `535 E 18th St`
         , `town` = `Flatbush - Ditmas Park`
         , `city` = `Kings`
         , `state` = `New York`
         , `country` = `United States`
         , `zipcode` = `11226`
         , `coordinates` = `40.63763458315378, -73.96082556740572`
         , `phone` = `4657345908`
         , `website` = `http://www.someurl.com`
         , `favoritebook` = `some book`
         , `aboutme` = `some details about me`
         , `birthdate` = `05-16-2012` 
     WHERE `id`  =  `42`
    here's my advice: don't use backticks!!
    Code:
    UPDATE jml_fl_users 
       SET street = '535 E 18th St'
         , town = 'Flatbush - Ditmas Park'
         , city = 'Kings'
         , state = 'New York'
         , country = 'United States'
         , zipcode = '11226'
         , coordinates = '40.63763458315378, -73.96082556740572'
         , phone = '4657345908'
         , website = 'http://www.someurl.com'
         , favoritebook = 'some book'
         , aboutme = 'some details about me'
         , birthdate = '05-16-2012' 
     WHERE id = 42
    note the birthdate value won't insert properly if birthdate is an actual DATE datatype

    note also there are no quotes around 42 because id is presumably a numeric column
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •