unable to modify specific column in mysql table - php

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

Related

Getting a Inserting Duplicate Key Error when value doesn't exist in table- SQL Server

We've got a web application that takes a uniquely generated workshop ID and calls a procedure (using php) and this procedure inserts it into a sql server table. This table has a clustered index on column workshopID and is set to unique.
This morning we had a user report that he got the following error code on his page:
Cannot insert duplicate key row in object 'dbo.table with unique
index 'ClusteredIndex-Wrkshp'. The duplicate key value is (Z9C1Am)
Obviously this suggests that I'm trying to insert Z9C1Am into the table and that value already exists---HOWEVER, when we do a simple lookup on that value, this value did not exist so I took the same stored procedure that the website code calls and used it to inserted Z9C1Am (using SSMS) into the table without any problem.
I can also get onto this application without any problems with this error; however, this same user called again and said he had the same issue (on the same computer) in another session. This time it had a different wordshopID in the error, but once again, this did not exist in the database.
I don't believe this has anything to do with inserting a duplicate key, rather, it is a phantom error.
Any suggestions on how to confirm this and how to track the actual error?
My gut reaction is this must be a browser related problem; however, all the code that interacts with the sql database is server side so this theory doesn't make much sense.
Thanks for the responses guys!
Greg's comment made me start looking harder at my dependencies and I have a join statement inside of my insert statement. The table I was joining to was supposed to contain unique values and approx. 25,000 of them are; however I had one set of duplicates causing the error.

Laravel PHPUnit failing on ALTER TABLE using SQLite

I have a migration which I made at the beginning of my project, basically adding a TEXT column called 'description' which is set to NOT NULL.
Now several months down the track I need to change that to allow null.
I can't use Laravel 5.5 change() function as I have a enum in my column list and it bugs out, so i need to add it as a raw query in a migration like so;
DB::statement('ALTER TABLE `galleries` MODIFY `description` TEXT NULL;');
When i do a php artisan migrate against my local mysql database it all works great, BUT when i try to run my test suite, it all breaks.
Im using SQLite for my test suite, and the error im getting is as follows;
PDOException: SQLSTATE[HY000]: General error: 1 near "MODIFY": syntax error
If anyone else has come up against this issue and fixed it, i would love to hear how you did it.
Thanks
SQLite only allows you to rename the table or add a column. The ALTER TABLE statement cannot change or remove columns.
In order to change or remove a column in SQLite, you need to create a new table with the desired schema, copy the data from the original table to the new table, delete the original table, and then rename the new table to the original name.
This is all abstracted out for you by Laravel and DBAL, so your best bet may be to get help with figuring out the issue with your enum column (though that would be a separate question).
You can read more about altering tables in the SQLite docs here.

Weird Duplicate Entry Error on Primary Key

I have a live project more than 5 years. And today i had a weird mistake. I wanted to update some of my products. And there exists a duplicate entry error.
I have no field as product_id in my products table. 12479 is id of my product. id is primary key and auto increment.
Firstly, i think it can be an laravel problem. I query mysql directly via phpmyadmin. It is same. But only for this product.
Here is my indexes.
Here is my table structure
I repaired my db from plesk also. Nothing change. Sometimes it works correctly.
Error from phpmyadmin
And the weirdest one is, this error occured when i update stock_quantity field. I can update other fields without problems.
I noticed a mysql bug while searching
MySQL Bug: https://bugs.mysql.com/bug.php?id=68360
What should i do ?
I solved problem. (Mysql Error Handling is not good. Descriptions must describe the situation better)
I had a trigger for stock_quantity. If a product sold out and get in stock again. I'm sending mail to customers. In that table(products_notify) product_id is unique. And the products which has ids on products_notify fails.
Thanks #Rodrane

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

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)

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