Jump to content

Error: Unknown column '' in 'where clause'

Go to solution Solved by gristoi,

Recommended Posts


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'].'"';
Link to comment
Share on other sites

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 -

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

Edited by mac_gyver
Link to comment
Share on other sites


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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.