user718359
user718359

Reputation: 515

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%One, Value%Two, Value%Three etc will that work? Ideas?

Upvotes: 1

Views: 1166

Answers (2)

Kalessin
Kalessin

Reputation: 2292

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' );

Upvotes: 1

Nicole
Nicole

Reputation: 33197

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.

Upvotes: 0

Related Questions