Mysql syntax error server version - php

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

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')

Unknown column "in field list form "

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

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'

Comparing 2 arrays and modifying 1

Ok, assume that I have 2 arrays.
$myArray = ('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
$badNumbers = ('3', '6', '10')
What I want to do is compare $myArrays with $badNumbers, then modify $myArrays to remove anything found in the $badNumbers.
So after some code, the end result would be:
$myArray = ('1', '2', '4', '5', 7', '8', '9');
$badNumbers = ('3', '6', '10')
Is there anyway to do this? I've of some things, but nothing seems to work. The comparing part alone I already have some problems.
EDIT: I'm fine with a third array too. Something along the line of for each value, if it doesn't appear in the second array, array_push to the new array. But I'm still not so sure on how to do this.
You can use array_diff to get the result.
$myArray= array('1','2','3','4','5','6','7','8','9','0');
$badNumbers= array('3','6','0');
$available = array_diff($myArray, $badNumbers);
print_r($available);
echo '<br /><br />' . implode(', ', $available);
Hope this helps.
$result = array_diff($myArray, $badNumbers);
echo count($result) ? 'there were differences' : 'there werent';
I suppose, array_diff() function does what you want.
What does "count" do? Is "echo" like "print"?
echo count($result) ? 'there were differences' : 'there werent';

Categories