Page 1 of 1

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

Posted: Fri Jan 14, 2005 4:59 pm
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

Posted: Fri Jan 14, 2005 5:39 pm
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. '