Php Error Code 1054
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error 1054 in MySql query up vote 0 down vote favorite I have following query: $query="SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value=". $data[$i]['label_value']." AND language=".$language_id; I have got the error: Error Number: 1054 Unknown column 'AccountPagesView.a_book' in 'where clause' But 'AccountPagesView.a_book' is value of $data[$i]['label_value'] and isn't a column. Where have I made a mistake? php mysql sql share|improve this question edited Jun 25 '12 at 9:01 totten 1,00521636 asked Jun 25 '12 at 7:47 user1477886 108417 instead of running query in mysql_query() first echo this query as a string in then copy it then run it in mysql yog or any sql gui to see how it works –raheel shan Jun 25 '12 at 7:53 add a comment| 2 Answers 2 active oldest votes up vote 3 down vote accepted You should enclose any string values in MySQL in ': $query= "SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value='". $data[$i]['label_value']."' AND language='".$language_id."'"; (I just took a guess, which are string-like columns.) EDIT As pointed out by @vstm: make sure the the values, you insert here, are properly escaped. share|improve this answer edited Jun 25 '12 at 7:59 answered Jun 25 '12 at 7:50 Sir
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL error 1054 up vote -1 down vote favorite I am trying to make my MySQL table insert stuff through MySQLi but it throws error 1054 Unknown Column saying that one of my values is my column, I dont know what causes this http://stackoverflow.com/questions/11185330/error-1054-in-mysql-query error. here is my code: $mysqli -> query('INSERT INTO `cities` (`Code`, `Name`, `lattitue`, `longitute`) VALUES ( `' . $_GET['code'] . '` , `' . $_GET['name'] . '` , `' . $_GET['lat'] . '` , `' . $_GET['long'] . '` )') here is the output: INSERT INTO cities (Code, Name, lattitue, longitute) VALUES ( kllk , kl , 9458 , 6568 )failed: (1054) Unknown column 'kllk' in 'field list' Thanks, help is greatly appreciated! php mysql mysqli share|improve this question asked May 26 '13 at 23:31 http://stackoverflow.com/questions/16764630/mysql-error-1054 user2421970 31 The accepted answer is wrong. How to include a PHP variable inside a MySQL insert statement –Your Common Sense May 27 '13 at 0:19 1 @YourCommonSense you're smoking stuff that's bad for you? a) I answer the question on how to fix the error, b) I then point towards documentation on parametrized queries as a better fundamental solution for the issue, to avoid c) the possibility of SQL injection which I link an explanation for, and d) I do it without, like you, linking to an explanation on how to fix this with a deprecated API. You're misinforming users on purpose, calling a fundamentally correct answer wrong, and linking to an outdated answer as 'better' without explanation - now that's just plain dumb. –Niels Keurentjes May 27 '13 at 0:29 add a comment| 1 Answer 1 active oldest votes up vote 1 down vote accepted Use real apostrophes (') around string constant values, not backticks (`) - those are used for escaping reserved words in queries. MySQL is now thinking you want to get the value for Code from a field named kllk instead of the string kllk as you seem to want. To the point, replace: VALUES ( `' . $_GET['code'] . '` with: VALUES ( \'' . $_GET['code'] . '\' And repeat this for the other values. After that make sure you go read up on parametrized queries, concatenating the values in there isn't good practice and could open up some nasty security exploits. share|improve thi
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://stackoverflow.com/questions/19212894/mysql-error-1054-unknown-column-in-field-list about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up MySQL error #1054 - Unknown column in 'Field List' up vote 8 php error down vote favorite 2 Whenever I try to input data into my tblorder I get the error message #1054 - Unknown column 'FK_Customer_ID' in 'field list'. I have tried breaking my code down and in doing this I found that the error is repeated for FK_Customer_ID and OrderQuantity whereas FK_DVD_ID it will take single data entries. I have tried dropping the table and recreating it, I have dropped the php error code database and recreated it but nothing works. As far as I can tell my code is correct along with my spelling so I'm really stuck. My tblorder is- CREATE TABLE tblorder ( Order_ID INT AUTO_INCREMENT NOT NULL, FK_Customer_ID INT NOT NULL, FK_DVD_ID INT NOT NULL, OrderDate DATETIME NOT NULL DEFAULT NOW(), OrderQantity INT NOT NULL, PRIMARY KEY (Order_ID), FOREIGN KEY (FK_Customer_ID) REFERENCES tblcustomer (Customer_ID), FOREIGN KEY (FK_DVD_ID) REFERENCES tbldvd (PK_ID) ); The data I am trying to put in is- INSERT INTO tblorder (FK_Customer_ID, FK_DVD_ID, OrderQuantity) VALUES (1, 3, 2), (1, 5, 1), (1, 10, 4), (1, 15, 3), (2, 5, 4), (2, 17, 3), (3, 15, 1), (3, 16, 1), (3, 17, 1); FK_Customer_ID is addressing - CREATE TABLE tblcustomer ( Customer_ID INT AUTO_INCREMENT NOT NULL, FirstName VARCHAR(50) NOT NULL, LastName VARCHAR(50) NOT NULL, Age INT NOT NULL, PRIMARY KEY (Customer_ID) ); FK_DVD_ID is addressing - CREATE TABLE tblDVD ( PK_ID INT AUTO_INCREMENT NOT NULL, Title VARCHAR(100) NOT NULL, DIrector VARCHAR(100) NOT NULL, Genre VARCHAR(40) NOT NULL, dvd_Year YEAR NOT NULL, Price FLOAT(2) NOT NULL, Quantity INT NOT NULL, PRIMARY KEY (PK_ID) ); Any help in fixing the will be greatly appreciated as it will help me with my A2 computing lesson! mysql mysql-error-1054 share|improve