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`
To fix the error above, simply add a quotation mark around the value. You can use both single quotes or double quotes as shown below: INSERT INTO users(username, display_name) VALUES ("jackolantern", 'Jack'); Now the INSERT statement should run without any error.
MySQL error code 1054 occurs if we forget to add single quotes while inserting a varchar value or due to any missing column.
If the given condition does not match any record in the table, then the query would not return any row.
The MySQL unknown column in field list error happens when you put a column name in your SQL script that can't be found by MySQL.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With