Hi
I am trying to run this query:

mysql_query("update group_data set title='$title', desc='$title' where groupid='$groupid'");

but the problem is that I get this 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 'desc='' where groupid='32'' at line 1

I could not see any problems in that query. I tried to update one value at a time; when I update the title filed only everything seems to work fine, but when I try to update the desc field I get the same error.

what is the problem?

Hi.

The word 'desc' is a reserved SQL keyword.
If you want to use it in a query like that, you need to enclose it in back-ticks. Like:

UPDATE group_data SET title='$title', `desc`='$title' WHERE groupid='$groupid'

hi
you can also rename desc fileld name is better way b'cos desc is used with order by clause in mysql


Thnaks

hi
you can also rename desc fileld name is better way b'cos desc is used with order by clause in mysql


Thnaks

Agreed. It's best to stay away from SQL keywords when naming your fields. (You can find a list of reserved words here)

It's also best to stay away from abbreviations and vague alterations to names. Like using desc rather than Description.
(Or did you perhaps mean Descendant, or did you misspell Desk... who knows?)

I don't agree. As long as you use correct cyntax (ie. `desc`) and as long as you know what `desc` means it isn't a problem. I use desc myself.

Hmmm.

It's depend on you that in which way want to go............

Thanks

I don't agree. As long as you use correct cyntax (ie. `desc`) and as long as you know what `desc` means it isn't a problem. I use desc myself.

You should never assume you are going to be the only one maintaining your code.
Not unless you can be 110% sure you are going to be the only one... in which case none of this matters in the slightest.

But... what if, in the future, you get a new job, or get promoted, or whatever... and somebody else has to take over.

Now this somebody has to struggle with all these vague field names that you knew so well.
Not to mention that this person might not be aware of keyword conflicts, which would cause him problems exactly like the one the OP is having.

Or, lets say, you leave this project for a few years, and when you come back you can't quite recall all of the vague field names.
Has happened to me, and probably most developers.

thank you guyes, Atli in particular.

As of the name confusion I always use the comment field in phpmyadmin in order to explain the function of every field, which I think would solve the problem of confusion for others.

Thanks again

Ahh nice, I didn't know you could directly add comments to tables and columns like that.

In a SQL query, that would be like:

CREATE TABLE `tTable` (
    `id` Serial Primary Key Comment 'This is the primary key',
    `title` VarChar(255) Not Null Comment 'The title of the row',
    `desc` Text Not Null Comment 'The description of the row',
    `created` TimeStamp Not Null Default CURRENT_TIMESTAMP Comment 'Pretty self explanatory, really'
)ENGINE=InnoDB DEFAULT CHARSET utf8 COMMENT 'A test table, just for fun!';

Thanks for the hint ;-)

Well, they would be screwed. All there is to it, good practive for him. Besides you only have to look at the script to figure out what the column is used for, for instance you wouldn't put desc in <tr><td>Name:</td><td><?=$row['desc']?></td></tr> LOL. Just pulling your leg. But seriously, I am stuck in the habbit now :P.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.