SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Database update problem

    Hi,

    I have some fields in a database that I need to update. These fields are called:
    1
    2
    3

    etc

    For some reason when I run my update SQL it always says that there is an error in my syntax, however if I run the exact same SQL on a field called a1, or anything starting with a letter then it runs fine.

    Can anyone help me get the SQL working without changing all the fields. They are used all over the site so I don't really want to change them if at all possible.

    The code I am using is:

    Code SQL:
    UPDATE TABLE_NAME SET 1='$var1', 2='$var2' WHERE id=17489

    Thanks so much

  2. #2
    SitePoint Addict
    Join Date
    Feb 2004
    Location
    Staffordshire, UK & Florida, USA
    Posts
    314
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't say which RDBMS you are using - I'm guessing it's MySQL or PostgreSQL. You could try using backticks (not single quotes) around the column names.

    Code SQL:
    UPDATE TABLE_NAME SET `1` = '$var1', `2` = '$var2' WHERE id = 17489

    Using columns names that are just numbers is definitely NOT a good choice, you should always try to give them meaningful names.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2006
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry, yes it is MySQL and your suggestion worked perfectly. Thanks very much.


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
  •