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

<?php

	$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) {
		var_dump($querystring);
	}	
				
	//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

medievalmanAsked:
Who is Participating?
 
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?
0
 
gr8gonzoConsultantCommented:
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?
<?php
$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?
0
 
gr8gonzoConsultantCommented:
Also, post your finished query.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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.
0
 
gr8gonzoConsultantCommented:
I don't think so - that error is just what you get back from MySQL.
0
 
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.