I can no usey "-" in my field names???

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

I can no usey "-" in my field names???

Post by Burrito »

I just created a new table and had some fields like:

user-name
user-pass

I tried to do an insert doing something like insrt into myTable (user-name,user-pass) values ('bob','bobby')

and it no likey.

I guess I could have tried to escape the "-"'s with "\" but figured that would cause a major headache down the road.

As soon as I replaced all of the "-" with "_" I"m good to go.

This is news to me that I can't use these..can anyone shed some light here?

thx,

Burr
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

they are allowed, however, because - is a math operation by default.. you need to tell mysql that the field name is, in fact a name, and not a math operation of subtracting pass from user, or name from user:

Code: Select all

INSERT. INTO `myTable` (`user-name`,`user-pass`) VALUES('bob','bobby')
note: the period after the insert should be removed, the server denies the posting otherwise.. :roll:

note: those are backticks, the quote character on the tilde key (~) not single quotes:

` vs. '
Post Reply