Unknown column "in field list form " - php

I am building a web app and I am submitting a form via ajax but I get 500 internal error, I am unable to figure out why it is showing unkown column since the field is present in the database.
A Database Error Occurred
Error Number: 1054Unknown column 'integrity' in 'field list'
INSERT INTO reportingofficers_part3 (plannedwork, qualityoutput, analytical, exceptionalwork, overall_workoutput, attitudetowork, responsibility, discipline, communication, leadership, teamspirit, timeschedule, inter_personal, personality, overall_personalattributes, Knowledgeofrules, strategic, decision, coordination, subordinates, handlingproblems, inspection, financialpropriety, overall_functionalcompetency, public_relation, training, health, integrity, reporting_officer_penpicture, overall_numerical_grading, id, reporting-officer-id, set) VALUES ('8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '8', '37' , '35', 1)
Filename: models/Login_model.php
Line Number: 193
and the snapshot of my reportingofficers_part3 table

Try to add "`" to table name and column names.
INSERT INTO `reportingofficers_part3` (`plannedwork`, `qualityoutput`, `analytical` ...
Additionally try to delete columns list and leave only values in query.

Soln 1:
is your id field auto increment ? if so please dont insert value '37' i see that goes to id primary key....and also
Soln 2:
You might check your choice of quotes (use double-/ single quotes for values, strings, etc and backticks for column-names)
please see the link for ref
Soln 3:
You can Drop that column and recreate that column in the same positon and try again...
i hope above answer will work...all the best

Try to use the backtick character on your columname, You should be aware that some names are usually reserved for mysql
e.g. SET is a reserved word and it has to have a backtick character before performing your MySQL query
follow this link for more detail
Therefore it should be something like
INSERT INTO reportingofficers_part3 (`plannedwork`, `qualityoutput`, `analytical`,
instead of
INSERT INTO reportingofficers_part3 (plannedwork, qualityoutput, analytical,
More so on the names that have been reserved for MySQL such as SET which you have used and you have not added a backtick onto it

Related

Column count doesn't match value count at row 1 error message, php / sql [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have to make a webpage using PHP and MySQL workbench to collect form data and I keep getting this error:
INSERT INTO tools ( id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10) VALUES ( '0','1', '2', '3', '4,' '5', '6', '7', '8', '9', '10')
INSERT failed: INSERT INTO tools ( id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10) VALUES ( '0','1', '2', '3', '4,' '5', '6', '7', '8', '9', '10')
Column count doesn't match value count at row 1
This is what my code looks like:
$query = "INSERT INTO tools ( id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10) VALUES ( '0','1', '2', '3', '4,' '5', '6', '7', '8', '9', '10')";
and this is what it looks like in workbench:
INSERT INTO tools (id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10) VALUES ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
I've tried it with an without the id and the 0 value, and neither work. Does anyone know how to fix this?
Your code
INSERT INTO tools ( id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10)
VALUES ( '0','1', '2', '3', '4,' '5', '6', '7', '8', '9', '10')
Has an error exactly between 4 and 5 the apostrophes are misspaced
It must look like this
INSERT INTO tools ( id, tool1, tool2, tool3, tool4, tool5, tool6, tool7, tool8, tool9, tool10)
VALUES ( '0','1', '2', '3', '4', '5', '6', '7', '8', '9', '10')

CI Is there a way to query custom order_by

Is it possible to customize the order_by query in MySQL or in CI ? Such as I want my column to be ordered by ('1', '11', '4', '2', '21', '3', '5', '7') So if I query it as ASC the result will show in the order of my customized order.
If it is not possible, what is the best workaround to get these order ? Hoping for a simple solution just using the MySQL query.
All answers and suggestions are greatly welcomed. Thanks.
Try this one.
$this -> db -> order_by('FIELD ( table.id, 1, 11, 4,2,21,3,5,7 )');
link
Pure Mysql answer is yes you can order a field by a set list with the MYSQL FIELD() function
SELECT *
FROM mytable
WHERE id IN ('1', '11', '4', '2', '21', '3', '5', '7')
ORDER BY FIELD(id, '1', '11', '4', '2', '21', '3', '5', '7')

Mysqli line 2 error how to isolate ' to not effect code outside the text areas

I am getting an error code "error on line 2" regarding apostrophes. I think what is happening is in the text fields when a ' is typed it is effecting the code outside the "" and causing an error. How do i make marks within the text field not effect the remainder of the code?
the html elements in question are q25 and q35
The site is live at http://educationofthedesigner.com/survey.html
after you submit it sends you to the php page.
error
__
Error: INSERT INTO survey2 (Email, School, Major, Degree, Status, Sex, Age, Q7, Q8, Q9, Classes,
Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27,
Q28, Q29, Q30, Q31, Q32, Q33, Q34, Q35, Q36, Q37, Q38, Q39, Q40, Q41, Q42, Q43)
VALUES ('', 'Purchase College', 'Graphic Design', 'BFA', 'Senior', 'Male', '1994', 'no',
'no', 'yes', 'branding, web/interactive, print, art direction, social design,
design theory, design authorship, type design, book arts, printmaking,
letterpress, design history', 'yes', '19 to 21', '11 to 20', 'no', '7', '3',
'1', '8', '2', '10', '3', '3', 'no', '30+', 'We don't focus on
skills/encouraging the development of a marketable portfolio at all.
There are students in my program who still don't understand basic precepts
of design, and more importantly don't understand how to teach themselves
new techniques. We're rooted in a homogenous visual culture that encourages
illiteracy in the tools of the trade as a hallmark of its style.', 'yes',
'studio', 'yes', 'yes', '20-25', '4', '2', '6', 'on capus', 'A drab closet
of a room filled with computers and devoid of windows and non-fluorescent
light. Big tables for cutting. No food or drink.', 'financial', 'yes', 'no',
'10', '7', 'yes', 'essential', 'Not Really')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 't focus on skills/encouraging the development of
a marketable portfolio at all. ' at line 2
I think that you are looking for Prepared Statements which should prevent from error like this.
First you create your statement and declare how many items you want to update/insert or whatever.
Than you declare type (s-string,i-integer) of variables and variables itself.
Look here: http://www.w3schools.com/php/php_mysql_prepared_statements.asp
You just need to escape apostrophes inside values apostrophes with slashes
INSERT INTO survey2 (Email, School, Major, Degree, Status, Sex, Age, Q7, Q8, Q9, Classes, Q11, Q12, Q13, Q14, Q15, Q16, Q17, Q18, Q19, Q20, Q21, Q22, Q23, Q24, Q25, Q26, Q27, Q28, Q29, Q30, Q31, Q32, Q33, Q34, Q35, Q36, Q37, Q38, Q39, Q40, Q41, Q42, Q43) VALUES ('', 'Purchase College', 'Graphic Design', 'BFA', 'Senior', 'Male', '1994', 'no', 'no', 'yes', 'branding, web/interactive, print, art direction, social design, design theory, design authorship, type design, book arts, printmaking, letterpress, design history', 'yes', '19 to 21', '11 to 20', 'no', '7', '3', '1', '8', '2', '10', '3', '3', 'no', '30+', 'We don\'t focus on skills/encouraging the development of a marketable portfolio at all. There are students in my program who still don\'t understand basic precepts of design, and more importantly don\'t understand how to teach themselves new techniques. We\'re rooted in a homogenous visual culture that encourages illiteracy in the tools of the trade as a hallmark of its style.', 'yes', 'studio', 'yes', 'yes', '20-25', '4', '2', '6', 'on capus', 'A drab closet of a room filled with computers and devoid of windows and non-fluorescent light. Big tables for cutting. No food or drink.', 'financial', 'yes', 'no', '10', '7', 'yes', 'essential', 'Not Really')
A basic example
INSERT INTO table (a, b, c) VALUES (1, 'hello', 'don\'t know');
-- ^ note the slash here
Or otherwise you can use php functions to deal with apostrophes as addslashes()
The errors occurs because mysql end the string to the first apostrophe found after the opening one for any values, the rest of the string will be not surrounded with apostrophe.
You should filter your form before adding data to database.
The easiest solution is to filter the data and remove apostrophe:
$string = str_replace("'", "", $string);
or if you prefer to have an apostrophe in your data use:
$string = str_replace("'", "'", $string);
Think about filtering other data, not only apostrophe.
Google for 'sanitize php' or 'filter input' for more information.

Mysql syntax error server version

Error
INSERT INTO PENILAIAN (ID,KURSUSID,QUEST1,QUEST2,QUEST3,QUEST4,QUEST5,QUEST6,QUEST7,QUEST8,QUEST9,QUEST10)VALUES ('951019105851', ''13'', '1', '2', '3', '4', '4', '5', '4', '5', '4', '5')
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '13'', '1', '2', '3', '4', '4', '5', '4', '5', '4', '5')' at line 3
code
"INSERT INTO PENILAIAN (ID,KURSUSID,QUEST1,QUEST2,QUEST3,QUEST4,QUEST5,QUEST6,QUEST7,QUEST8,QUEST9,QUEST10)VALUES
('$login_sessionID',
'$kid','$QUEST1','$QUEST2','$QUEST3','$QUEST4','$QUEST5','$QUEST6','$QUEST7','$QUEST8','$QUEST9','$QUEST10')";
Error simply guides you
''13''
^ ^
there is additional single quote
keep only one ' pair for code
Use prepared statements
I think you have double quotes on ''13''.
olso i want to ask, does any of the values contain quotes? like this (I'am x)
if you use quotes you should use mysql_real_escape_string when you POST

I need to change a complex MYSQL query in to a view or views

I have a query that creates a rolling sum and subtracts that from a sum total. I have the query working in the SQL window, but I need some help changing it in to a view or table that I can call from a PHP so I can use the results in building a graph.
This query builds the basis for a burndown report used in project management so it is very handy.
When I try to create a view out it I get multiple errors with joins and variables not being allowed in a view. I am kind of a mysql newbie and I am beating my head on this one.
Here is the SQL query:
SELECT
taskid,
projectid,
esthours,
actualhours,
eview.SE As TotalHours,
(#EST:=#EST - esthours) as ESTI,
(eview.SE + #EST) as Estimated,
(#EST2:=#EST2 - actualhours) as AC,
(eview.SE + #EST2) as Actual
from
tbltasks,
eview
JOIN
(SELECT #EST:=0) EE
JOIN
(SELECT #EST2:=0) E2;
Here is a sample of the results.
taskid, projectid, esthours, actualhours, TotalHours, ESTI,Estimated, AC, Actual
'1021', '2', '4', '3', '20', '-4', '16', '-3', '17'
'1022', '2', '3', '3', '20', '-7', '13', '-6', '14'
'1023', '2', '2', '4', '20', '-9', '11', '-10', '10'

Categories