开发者

MySQL - I have an issue with blank space

I have a drop down list on a form with values:

Value One
Value Two
Value Three

The values go into a db.

I have another db with columns

Value One
Value Two
Value Three

I have an IF statement that if form Value One to get records in db from Colum Value One.

But getting error message Unknown column 'Value' in 'field list'

I think it has to do with the space? Can I have spaces in the names in MYSQL? If I change it to Value_One, Value_Two, Value_Three can I change the form input Value to be Value%开发者_StackOverflow中文版One, Value%Two, Value%Three etc will that work? Ideas?


It's always a little harder to debug without seeing your code -- the offending SQL statement for example -- but you might benefit from referring to the column as `Value One` (note the backtick quote marks).

Update: response to comment

This works for me:

INSERT INTO `test_db` ( `Value One` ) VALUES ( 'Test data' );


You can wrap column names, table names, and other identifiers that contain spaces or keywords (like "select") with backticks:

`Value One`

However, from the sound of it, I'm not sure that is your only issue. A use case where you select a column name in a form and submit it is a strange one.

Is it possible that you are trying to get the values from a single column of the database, instead of multiple columns?

Use DESC tablename to find out the column names.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜