I have a PHP script and for some reason mysql keeps treating the value to select/insert as a column. Here is an example of my sql query:
$query = mysql_query("SELECT * FROM tutorial.users WHERE (uname=`".mysql_real_escape_string($username)."`)") or die(mysql_error());
That turns into:
SELECT * FROM tutorial.users WHERE (uname=`test`)
The error was:
Unknown column 'test' in 'where clause'
I have also tried:
SELECT * FROM tutorial.users WHERE uname=`test`
I also faced the issue of "Unknown column in where clause" when executing the following from linux (bash) command line.
This is what I got
I had to replace the single quotes 'test01' with double quotes "test01" . It worked for me. There's a difference how and the way you're executing sql queries.
When assigning a value to a variable in a script and later, using that variable in a sql statement that has to be executed by the script, there's slight difference.
If suppose variable is
and you want to pass this value from within script to mysql, then single quotes work.
So different engines might evaluate backticks and quotes differently.
This is my query that worked from linux command line.
In MySql, backticks indicate that an indentifier is a column name. (Other RDBMS use brackets or double quotes for this).
So your query was, "give me all rows where the value in the column named 'uname' is equal to the value in the column named 'test'". But since there is no column named test in your table, you get the error you saw.
Replace the backticks with single quotes.
Weird? How so? It says exactly what's wrong. There is no 'test' column in your table. Are you sure you have the right table? 'tutorial.users' ? Are you sure the table isn't named differently? Maybe you meant to do
You have to reference only the table name, not the database.. assuming the database is named
tutorial
example:
Note the single quotes around the $uname. When you echo the query, this is the output-
However if you miss the quote around the $uname variable in your query, this is what you'll get-
On MySQL server, the 2 queries are different. thierry is the input string and correctly encapsulated in quote marks, where as in the second query, it isn't, which causes an error in MySQL.
I hope this helps and excuse my englis which is not very good
I had the same issue and it turned out to be a typo. My error message was:
I checked that very column in my table and it turns out that, I had spelt it as "depature" and NOT "departure" in the table, therefore throwing the error message.
I subsequently changed my query to:
and it worked!
So my advise clearly is, double check that you spelt the column name properly.
I hope this helped.