Advanced Search

Results 1 to 5 of 5

Thread: Why does this character affect a query?

  1. #1
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why does this character affect a query?

    I've been trying for the past couple of days to figure out why I kept getting an error on my update query in php/mysql.

    This is the original query I was having trouble with:

    PHP Code:
    $update="UPDATE videos SET title='$title', date='$date', 
    desc='
    $desc',  image='$image', sample='$sample', 
    clip1='
    $clip1', clip2='$clip2', clip3='$clip3', clip4='$clip4', 
    clip5='
    $clip5', clip6='$clip6', clip7='$clip7', clip8='$clip8',
    full='
    $full', active='$active' WHERE id='$_GET[id]'";
    $updateresultmysql_query($update) or die(mysql_error()); 
    The error stated:
    Code:
    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 'desc='testing update do no', image='img.jpg', 
    sample='t543653et.wmv', clip1='t3' at line 1
    As soon as I added this character ( ` ) to my DESC section of the query it worked fine.

    like this: `desc`='$desc'


    Can anyone explain to me why that character affected the query so that it would work when I didn't need to use that on any of the other parts of the query?

    -dro
    Last edited by Snookerman; 04-22-2009 at 02:05 PM. Reason: added “Resolved” prefix

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Using the back ticks ( ` ), it prevents mistakes of reserved words, for example:

    If I had a table named AND, I would tick it to not cause further mistakes.
    Jeremy | jfein.net

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

    Default

    Yea, desc would stand for "ORDER BY DESC" (descending)

    You must use ticks or you'll get an error.

  4. #4
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Awesome, I don't know why I didn't catch that when I was calling the table "desc" but thanks for clearing that up for me! I learn something new every day!

  5. #5
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Great! Glad to help you! Your welcome!

    It seems your topic is solved... Please set the status to resolved.. To do this:
    Go to your first post ->
    Edit your first post ->
    Click "Go Advanced" ->
    Then in the drop down next to the title, select "RESOLVED"
    Jeremy | jfein.net

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
  •