Unknown column 'valueToPass' in 'field list' MySQL Error # :1054 - php

I have written a stored procedure in mysql to update. That is working fine, when you execute it in the mysql command line(through Mysql editor).
Stored procedure is:
CREATE DEFINER=`root`#`localhost` PROCEDURE `Deduction_Of_PL`(
IN P_EMPID VARCHAR(1000)
)
BEGIN
DECLARE PresentYearPL VARCHAR(1000);
set PresentYearPL=(select Present_Year_PL from leave_calculate_pl where employee_id=P_EMPID);
IF(PresentYearPL<=0) THEN
UPDATE leave_calculate_pl
SET Carrie_PL=Carrie_PL-1
where employee_id=P_EMPID;
ELSE
UPDATE leave_calculate_pl
SET Present_Year_PL=Present_Year_PL-1
where employee_id= P_EMPID;
END IF;
END $$
And I calling the same Stored procedure in PHP, I am passing the input parameter also.
$LeaveTypeID_G=$this->getLeaveTypeId();
$query_G="CALL Deduction_Of_PL($LeaveTypeID_G)";
Its giving the error as
Unknown column 'parameter_value' in 'field list' MySQL Error # :1054
Please let me know where went wrong and how can I resolve it.

I've just come up against the same issue. I'm trying to pass a logged in user's username to the stored procedure to record it in a log.
The Stored Procedure runs fine when I call it directly (from MySQL Workbench) and was working fine from PHP when I was only passing a date/time. Now that I'm passing this username as a string, however it broke.
For me the fix was to enclose any string parameters in single quote, something like this:
$query = "CALL $procedure_name ( $date_parameter, '$string_parameter')";
Hope that helps anyone else stumbling across this.

well I'm not an expert on sql, and I don't see much php code posted but "Unknown column" to me would be refering to the column names in the sql table in question, or more precisely that it can't find the column you told it to get in that table. first place I'd look at is the select statement your asking it to pull from the column "Present_Year_PL" I found this to be case senstive so make sure it matches excatly the column name on the table. next place I'd look is in the where statement you told it to match agist the colum "employee_id" now this is all lower case as oposed to your prevous column name that was all caps, while this is technicaly legal, (As on the actual table you could have one column in all caps and one in all lower,) usally if all caps are used in one column name in a table all the column names are done the same, and vice versa. this would cause a problem your having if say the "employee id" column on the table is "EMPLOYEE_ID" as then "employee_id" actualy does not exist in the table. also be sure your not dooing sometthing like "employeeid" or "employee-id" or even "employee id" as those are verry easy to mistake when eyeballing the field name but will give you the error your getting.

couple of pointers:
what is the value of the php variabele $LeaveTypeID_G? echo $LeaveTypeID_G; (php)
secondly is MySql invoking a trigger? show triggers; (mysql)

Related

unable to modify specific column in mysql table

I seem to be having an issue when updating records on a specific table.
For reference here is an example of the query that throws an error:
UPDATE `dbname`.`tblname` SET `CustomerID` = '543' WHERE `tblname`.`Issue_ID` = 440
I am able to insert, delete and query rows, as well as update other columns however whenever trying to update the CustomerID field (int, non-null) it throws an error saying:
#1054 - Unknown column 'Revision' in 'field list'
I have all rights to both the database and table however while trying to update the CustomerID column on any rows, ever when Revision isn't even in the query I get the same error.
I looked around a great deal into the issue using a regex in my php code to remove all non-printable characters however even when running the query from phpMyAdmin the same error is thrown.
If anyone has insight into this error it would be greatly appreciated.
Table description:
You may possibly encounter this if you have an update trigger firing off which is referencing a column that does not exist. May be the offending trigger is not even trying to read/write to this table! As such, that column may not exist where it is trying to reference it. Further, you could kick off a cascade of such triggers, and have this buried more than one layer deep.
To show triggers:
http://dev.mysql.com/doc/refman/5.7/en/show-triggers.html
To modify them:
http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html

Duplicate entry '0' for key 'PRIMARY' in empty table

I am currently starting web development and am now working on a very simple script that posts entry data from a from to a mysql database. But the problem I have been encountering is that when I submit the form I get the following error:
Error: Duplicate entry '0' for key 'PRIMARY'
To me it seems a really weird error as the table is completely empty, ID is set to auto_increment and I am not trying to assign any value to it.
I am using Xampp for my localhost on Mac OS btw.
This is my form (.php):
This is my mysql entry script (.php):
The result is this:
This is the database setup:
The weird thing is that when the table is empty, and I insert through the form the first time, something does end up in the database. But it is missing "email" and "password" and shows "NULL". The second time I use the form, nothing is added in the database:
Your id column does not seem to be auto-incrementing. It is not generating a new id for every row. It just defaults to 0 if you don't supply a value for it.
Nonetheless there's a UNIQUE/PRIMARY constraint on that column, so the id 0 cannot occur more than once. Since you're not supplying an id and MySQL isn't generating one (because the column isn't auto-incrementing), you cannot insert more than one row.
You're issuing three separate INSERT INTO statements which will result in three separate rows to be inserted (if you could insert more than one row, see above), each with a different value set; but never one row with all values set.
So:
Make your id column actually auto-incrementing.
Prepare a single INSERT INTO statement which inserts all values in one go:
INSERT INTO members (name, email, password) VALUES (.., .., ..)
See Why shouldn't I use mysql_* functions in PHP? and stop using mysql_*. Learn about prepared statements, read The Great Escapism (Or: What You Need To Know To Work With Text Within Text) for why.

Alter Tabled using PHP Query, Column Name doesn't show up in phpMyAdmin

This is my first post, and there is a similar post here: phpMyAdmin doesn't show added columns - Stack Overflow
But since no one has answered, I will ask here and provide more details in hoping to resolve this issue. I have a table in my database that I needed to be able to add additional columns to. I've done this using the following query:
$sql = "ALTER TABLE tablename ADD columnname INT(11)"; //Run the query....
This worked perfect on day one, however on day two when I tried to add an additional column via this php script, it appears to work from the phpMyAdmin Structure view. The column is in there with the correct columnname and datatype. However when I switch to the Browse view, there is no Column Name, just blank columns filled with "null" values. But, if you click on an individual row, it shows the correct column name, and a value (if one exists for that row).
I've tried running Analyze Table, as I read somewhere that that would update the Schema. However, I haven't had any success with that fixing it. I'd prefer to not have to delete the table and restart, especially if I run into this issue again. As this is my first post, I've tried to format everything correctly, but please forgive me if I didn't. Also, I can grab screenshots if anyone is having issues understanding my question.
if you can, restart mysql, it should flush everything, including mysql caches phpmyadmin may be using.

MySQL AUTO_INCREMENT Manual

Let's say I have a MySQL table and a table has a row with id and it has auto_incremented. Let's say via MySQL query and PHP, I add a row. The first row has id of 1. Then I manually add a second row (via phpmyadmin) with the id of 2. If I do a third MySQL insert via PHP... what would the id be for the third row... 2 or 3?
Question is... does auto_increment take into account manual inputs?
does auto_increment take into account manual inputs?
Yes it does. But I hope you do not really type in the ID manually, right? :-) Just leave this field alone when inserting (manually or programatically), MySQL will take care of it for you.
MySQL does accept manual inputs, and it WILL try to set the value you offer. If the value does not exist, it gets inserted, else you get a duplicate key error.
Put a value when you want to decide a value yourself (for example,
you deleted a line, and now want the exact same line in the table).
Put NULL or leave the column out of the insert to let the database
use the auto-increment.
Just a hint: when your application is choosing the values to put for an autoincrement value, you are probably doing something wrong.

Unknown column in 'field list' error on MySQL Update query

i echoed the query below: (query is safe)
UPDATE otelozellik
SET isim_tr='test',
aciklama_tr='<p>test1</p>',
uyari_tr='test',
tag_tr='test'
WHERE id='1'
Database Error: Unknown column
'aciklama_tr' in 'field list'
I changed the order of columns, the one after isim_tr keeps giving error. When I move isim_tr to the last then the one after id giving the same error. But moving them to the last position is not a solution for me because table will be dynamic to add new columns when necessary. need an absolute solution.
UPDATE: LATEST SCREENSHOT: http://img5.imageshack.us/img5/7215/mysqlerror.jpg
Solved. Solution is answered below. Thanks everyone.
Problem is solved. Thank you a lot everyone for their help.
Right Query for solution is:
UPDATE `holidaycholic`.`otelbilgi` SET `otelbilgi`.`isim_tr`='test2', `otelbilgi`.`aciklama_tr`='<p>test2</p>', `otelbilgi`.`uyari_tr`='test2', `otelbilgi`.`tag_tr`='test2' WHERE `otelbilgi`.`id`=1
No idea why but that worked for me.
'field list' errors are caused when you try to load data into a field that doesn't exist. Double check that you spelled your field names correctly.
Your post says that you need to add "dynamic columns". A properly structured database shouldn't have a need for that sort of thing. However, if you do want to add columns from php, you need to add them to the table before you try to insert data in those fields. You can use the ALTER TABLE statement to do this:
ALTER TABLE table_name
ADD column_name datatype
Just to double-check are all the characters you're using the standard ASCII characters or are you using an unusual character set?
Try inserting data into the table using phpMyAdmin or similar - If it works, copy the code it generates and run it yourself using the mysql client.
Assuming that still works, compare the generated code with the SQL generated by your PHP
Here is the syntax which works for me all time:
"INSERT INTO table(`code`, `description`) VALUES ('".mysql_real_escape_string($code)."', '".mysql_real_escape_string($description)."')";
"table" is a table with an AUTO_INCREMENT index.

Categories