Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Update Table Query

    I'm struggling to get the below query to work. Basically, I just want to set the field to 0 for all rows.
    PHP Code:
    $sql "UPDATE TABLE game_84 SET mission = \'0\' "

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    It would help if you gave us the error you are getting.

    From what I can see you have one syntax error and one potential problem. The word "TABLE" doesn't belong-- the syntax is "update tablename set fieldname = value where condition".

    The potential problem depends on the data type of your field "mission". If it is a char, or varchar, then you do indeed need the quotes as you have them. If it is an integer, then you should not include the quotes.

  • #3
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    ...also in php, within double quotes, \' means literal backslash + literal single-quote.
    PHP Code:
    $x "\'";  // string of 2 characters: backslash + single quote 
    so MySQL will 'see' the backslashes which is not what you want.

    With Fumigator's correction, this would probably have been fine:
    PHP Code:
    $sql "UPDATE game_84 SET mission = '0'"


  •  

    Posting Permissions

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