Quick SQL problem

Discussion in 'PHP' started by nick-a, Dec 27, 2007.

  1. #1
    $editquery = "UPDATE ads SET 468='$a468', 720='$a720', 300='$a300', 120='$a120', 160='$a160' where user='$user'";
              
    mysql_query( $editquery ) or die ( "Update error: ".mysql_error() );
    Code (markup):
    This produces the error: Update error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '468='grrewhba', 720='reaghhrgreagg', 300='rgaerg', 120='eargeearg', 160='rgagra'' at line 1

    But I can't see anything wrong with it?

    Cheers,
    Nick
     
    nick-a, Dec 27, 2007 IP
  2. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Here my universal solution for all kind of mysql problems :)

    Echo "query" statement, copy it and paste it into phpmyadmin and try to see what errors are. Then generate with phpmyadmin a valid query statement using same fields/criteria and compare the two statements to see what's different and how should you modify the original query to make them look and behave the same.

    Try it :)
     
    hogan_h, Dec 27, 2007 IP
  3. nick-a

    nick-a Active Member

    Messages:
    446
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks, but hasnt really helped, the result was full of a ridiculous amount concatenation etc, which isn't necessary....
     
    nick-a, Dec 27, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, if you don't want to take over phpmyadmin concats, happy error hunting then :)
     
    hogan_h, Dec 27, 2007 IP
    nick-a likes this.
  5. nick-a

    nick-a Active Member

    Messages:
    446
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #5
    It's not that I don't appreciate the advice, I do, I've used that method before, but it doesn't work very well in this situation:

    $sql = 'UPDATE `ads` SET `468` = \'blah'
    . ' trhrths\', `720` = \'blah'
    . ' rhesrjh\', `300` = \'blah'
    . ' esrhes\' WHERE `ads`.`id` = 0 LIMIT 1;';

    When

    $editquery = "UPDATE ads SET 468='$a468', 720='$a720', 300='$a300', 120='$a120', 160='$a160' where user='$user'";

    mysql_query( $editquery ) or die ( "Update error: ".mysql_error() );

    Should work fine?
     
    nick-a, Dec 27, 2007 IP
  6. nick-a

    nick-a Active Member

    Messages:
    446
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Ahh if I wrap the column id's with ` ` it works fine, never had to do that before, seems sql statements dont like plain old numbers as the col id's without the ` round them.
     
    nick-a, Dec 27, 2007 IP
    hogan_h likes this.
  7. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Yeah, just wanted to say that you at least should use backticks for column names, because i never saw anyone using numbers as col.names.
     
    hogan_h, Dec 27, 2007 IP