Jump to content

Error: Unknown column '' in 'where clause'


lasha

Recommended Posts

  Quote

 

needs to be surrounded by single-quotes

 

@mac, why only by single-quotes? The values of string type just need to be quoted. I've never use double quotes to quote the value with char/varchar or date/time type but the following should be worked as well.

$query = 'SELECT * FROM car WHERE owner = "'.$_POST['owner'].'"';

because, double-quotes can be enabled (a sql standard) to be used the same as back-ticks (a mysql specific abomination) and used around database, table, and column names, thereby breaking any query using double-quotes around string data and making it difficult to migrate to other database types -

  Quote

If the ANSI_QUOTES SQL mode is enabled, it is also allowable to quote identifiers within double quotes:

did you look at the OP's problem? he's getting an unknown column error because his $_POST['owner'] value has no quotes around it at all, producing a query - SELECT * FROM car WHERE owner = some_owner_name and the some_owner_name value is being interpreted as a column name.

  Quote

 

did you look at the OP's problem?

Yes, I do! In that case "owner" is the identifier, its value it is a constant named "some_owner_name". So, in the cite you cited above we can allowable to quote identifiers within double quotes, like this: SELECT * FROM car WHERE "owner" = some_owner_name.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.