SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict nabeel's Avatar
    Join Date
    Nov 2002
    Location
    in westchester county, ny
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    what's wrong with this query?

    Hi all,

    I can't quite figure out what the problem with this query is...
    PHP Code:
    $result mysql_query("UPDATE gallery SET caption='$name', link='$url', thumburl='$thumburl', desc='".addslashes($desc)."' WHERE id='$id'" );
    if(!
    $result){
    echo 
    "Could not update the image there was an error<br>";
    echo 
    mysql_error() . "<br>";
    }
    else
    echo 
    'Updated the image<br>';

    I don't understand the error:

    "You have an error in your SQL syntax near 'desc='yes ' WHERE id='157'' at line 1"

    That line is on #165, but it says line 1. Line 1 is a <?, there's no other errors or anything.

    I've also tried other thing like putting the addslashes() before the UPDATE statement, and $desc=addslashes(htmlspecialchars($desc));
    Still the same error.

    I don't see anything wrong with the syntax either

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the word 'desc' might be a reserved word. Try renaming the field

    Hope this helps.

    -Sam
    Sam Hastings

  3. #3
    SitePoint Addict nabeel's Avatar
    Join Date
    Nov 2002
    Location
    in westchester county, ny
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohhhhhhhh it works now, good call. thanks alot

  4. #4
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or you could have used backticks:

    update table set `desc`='blah'
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  5. #5
    SitePoint Member
    Join Date
    Feb 2002
    Location
    North Carolina
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you can use backticks, but it would be a good idea to just choose a name that isn't an SQL keyword.
    Deluxe Portal Project Manager


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
  •