MySQL - Error 1054 : Unknown column in 'field list' when column actually exists.

I have a simple update query that is failing with the following errror...

Error 1054 : Unknown column 'Display' in 'field list'

The column does exist in the database and I have checked to make sure there are no spaces or anything quirky like that going on. I have tried moving, dropping, and re-creating the columns with no success. I am using MySQL version 5.6.17 The code that produces the error is as follows...


	$post_title = trim(mysqli_real_escape_string($db, $_POST['Title'])); 
	$post_longdescription = trim(mysqli_real_escape_string($db, $_POST['LongDescription']));
	$post_laborrate = $_POST['LaborRate'];  
	$post_display = (int) $_POST['Display']; 
	$post_id = (int) $_POST['LaborerId']; 

	$querystring =  " UPDATE myTable";
	$querystring .= " SET ";
	$querystring .= " Title = '{$post_title}',";
	$querystring .= " Display = $post_display,";
	$querystring .= " LongDescription = '{$post_longdescription}',";
	$querystring .= " LaborRate = $post_laborrate";
	$querystring .= " WHERE LaborerId = " . $post_id;
	//spew the query string if set
	if(isset($_GET['showquery']) && $devmode) {
	//Query was unsuccessful
	$result = mysqli_query($db, $querystring);
		if(!$result) {
			if($devmode) {
				die("Error " . mysqli_errno($db) . " : " . mysqli_error($db));
			} else {
				die("An error has occured. Please contact the system administrator.");			 	
		if(!mysqli_affected_rows($db)) {
			die("No matching rows found. Please contact system adminstrator");

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1. Double-check to make sure you're connecting to the right database. :) I've seen people forget that they're connecting to a development database, which doesn't have the latest columns, and when they check to see if the column exists, they check a production database or something, so they THINK it's there, but it's really just a different database.

2. Do you use column permissions at all?

3. What happens if you run a query to show the columns?
$result = mysqli_query($db, "SHOW COLUMNS FROM MyTable");
while ($row = mysqli_fetch_assoc($result)) { print_r($row); }

Open in new window

What's the output there?
Also, post your finished query.
medievalmanAuthor Commented:
Positive I am using the correct db because it's an include file used for each connection. If I dump $querystring to the screen and then copay and paste into phpAdmin, where it actually shows the field for the table, it still fails with the same error. As for the results of that query you asked me to run...

Array ( [Field] => LaborerId [Type] => int(11) [Null] => NO [Key] => PRI [Default] => [Extra] => )
Array ( [Field] => Title [Type] => varchar(100) [Null] => NO [Key] => [Default] => [Extra] => )
Array ( [Field] => LongDescription [Type] => longtext [Null] => YES [Key] => [Default] => [Extra] => )
Array ( [Field] => LaborRate [Type] => decimal(18,3) [Null] => NO [Key] => [Default] => [Extra] => )
Array ( [Field] => Display [Type] => tinyint(1) [Null] => NO [Key] => [Default] => 1 [Extra] => )

Thanks for your help.
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

medievalmanAuthor Commented:
Found my own faux pas. The problem was that there was a Trigger set for updates on the table that copied the record into another table. The table the trigger was copying to did not have the field "Display" in it. The error messages that were being displayed back to me (both php and phpmyadmin) mentioned nothing about the Trigger or the actual table causing that failure. I guess the question now would be is there a more verbose error system I should be using?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I don't think so - that error is just what you get back from MySQL.
medievalmanAuthor Commented:
Remember to check and see if underlying Triggers could be the cause of an error where it appears your SQL is correct. MySQL did not tell me it was a different table or a trigger causing the error. Just that there was an error.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.