Log in

View Full Version : Resolved Why does this character affect a query?



DeSaaD37
03-16-2009, 11:03 PM
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:


$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]'";
$updateresult= mysql_query($update) or die(mysql_error());

The error stated:

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

Nile
03-17-2009, 01:09 AM
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.

Schmoopy
03-17-2009, 01:21 AM
Yea, desc would stand for "ORDER BY DESC" (descending)

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

DeSaaD37
03-17-2009, 01:41 PM
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!

Nile
03-18-2009, 11:25 PM
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"