Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: sql query number vs string

  1. #1
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default sql query number vs string

    when i update a table like this, it worls
    Code:
    UPDATE tableName SET itemID=523 WHERE descript_1 LIKE 'nameOfItem';
    but when i update it as a string, it doesnt work
    Code:
    UPDATE tableName SET differentItemID='someString' WHERE descript_1 LIKE 'nameOfItem';
    what is going on?
    Last edited by ggalan; 12-21-2010 at 09:34 PM.

  2. #2
    Join Date
    Jul 2010
    Location
    Minnesota
    Posts
    256
    Thanks
    1
    Thanked 21 Times in 21 Posts

    Default

    What is the string you are trying to update? You can always add
    PHP Code:
    or die(mysql_error()) 
    to the end of your query and that will give you an error if the query is failing due to a snytax error in the string or otherwise.

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Is that column set to bit, int, float, or some other only numerical input?

    fastols solution may give more results assuming you are using mysql, if not we will need to know what db you are using and what the column is set as.
    Corrections to my coding/thoughts welcome.

  4. #4
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    it was set to "varchar(20)"

  5. #5
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    And did you get anything from mysql_error()? Assuming you're using MySQL...

    If there's no error, what's it updating that field with?

  6. #6
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    #1064 - 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 'differentItemID='someString' WHERE descript_1 LIKE 'nameOfItem'' at line 1

  7. #7
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Try using backticks for the column name:

    Code:
    UPDATE tableName SET `differentItemID`= 'someString' WHERE descript_1 LIKE 'nameOfItem';
    I can't imagine that this would cause the problem, are you sure the code above is exactly what's going into the query? (minus the backticks).

    Try echoing the SQL out just before you execute it.

    From what you've posted, you should be getting an error along the lines of:
    Code:
    "SQL Error (1146): Table 'databaseName.tableName' doesn't exist".
    (I executed the above query through HeidiSQL)

  8. The Following User Says Thank You to Schmoopy For This Useful Post:

    ggalan (12-21-2010)

  9. #8
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    the backticks solved it! weird
    i always thought that ` was the same as '
    how do i get those backticks from my keyboard?

  10. #9
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Not sure what keyboard you have, but on mine (American English), the backtick is to the left of the "1" key. Should have like 3 symbols on it.

    If you're not using this type of keyboard, then see if anyone else knows where it is.

  11. #10
    Join Date
    Jan 2008
    Posts
    441
    Thanks
    67
    Thanked 4 Times in 4 Posts

    Default

    got it `, lol
    but back to the original question, why would i need those backticks for the sql query to work?

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
  •