Jump to content


Photo

query issue


  • Please log in to reply
6 replies to this topic

#1 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 03 January 2006 - 10:06 PM

hey there,

I got a new host for a new site i made and i have a bit of issue with the mysql system on the new host.

first off they have register_globals set to off which i have made adjustment to but when i try to enter a query like this:

insert into ebb_category (Name, Order) values ('$name', '$order')

i get this error:

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]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 'Order) values ('General', '2')' at line 1[/quote]

now that table has 3 columes but that colume is the id which i set to auto incredment, so any idea on how to make this work.

much thanks.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 January 2006 - 11:28 PM

Well, there's nothing wrong the SQL syntax, but you're using a reserved keyword -- Order -- as one of your column names. Very, very bad idea, since you have have to enclose any reference to this column in backticks:

insert into ebb_category (Name, `Order`) values ('$name', '$order')

I STRONGLY urge you to change you field name at the earliest opportunity -- this is going to be a hassle FOREVER.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 LazyJones

LazyJones
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 03 January 2006 - 11:45 PM

It's a pity that using reserved words is even allowed in mysql (maybe other database engines too). Does it even give a warning about it? or do I need to test it to find out :)


#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 January 2006 - 12:37 AM

No warnings, just errors -- though it you use a decent GUI with syntax highlighting, it won't happen ever. Furthermore, it just indicates that you've chosen very poor column names that aren't very descriptive. BTW, you can usually get away with reserved keywords in most languages with enough escaping/scoping.

BTW, LazyJones, speaking of name choices, your sig has an mistake in it... ;-)
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 darkcarnival

darkcarnival
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts

Posted 04 January 2006 - 01:06 AM

your kidding?

ok ill have to rename that then.

i thought order by was just not allowed

but yes a warning should appear to let me know since ive been ripping my hair out over this all week.

thanks a bunch.

#6 LazyJones

LazyJones
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 04 January 2006 - 01:12 AM

[!--quoteo(post=332944:date=Jan 3 2006, 07:37 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Jan 3 2006, 07:37 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]

BTW, LazyJones, speaking of name choices, your sig has an mistake in it... ;-)
[/quote]

OMG, thank you for that :)

And I've been having it whole day...

Added this after answering the same way for 30+ times...

#7 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 04 January 2006 - 06:48 AM

[!--quoteo(post=332956:date=Jan 3 2006, 08:06 PM:name=darkcarnival)--][div class=\'quotetop\']QUOTE(darkcarnival @ Jan 3 2006, 08:06 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
i thought order by was just not allowed
but yes a warning should appear to let me know since ive been ripping my hair out over this all week.
[/quote]

The problem really is the when the parser hits the word "order", it expects it to be followed by "by" -- it has no idea that you _wanted_ it to be your field name. Sure, it could, but that would make the parser incredibly slower.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users