I have a query that save zero in one of the MySQL column.
Column was set to be NULL = no and Default = none. But my query wasnt working when i had that structurer when I save 0. So i change the value to null. But when saving 0 (zero) in database its still getting saved NULL.
When i had the column set to be NULL = no and Default it was working fine on my localhost but in my hosting query wasn't getting inserted. that is why i change it to null.
MySQL version 5.6.30
Query
$mysqli->query("INSERT INTO categories(cname, cat_description, cat_ parent) VALUES ('$cname', '$description', '0')");
You are actually trying to insert a string in an integer column. MySQL does not accept this. And it shouldn't.
Insert an integer:
$mysqli->query("INSERT INTO categories(cname, cat_description, cat_ parent) VALUES ('$cname', '$description', 0)");
Just remove the quotes around 0.
Related
Using MySQL (MariaDB 10.4.12)
I am trying to update a column using the replace function. I need to replace an ip address with a URL. The value in the column is very long.
I am using:
UPDATE myTable
SET myColumn = REPLACE(myColumn, '192.168.9.1', 'www.mydomain.com/content')
WHERE ID = 1234;
When I run this, the value it updates to is very wrong.
However, if I remove the"/content" from the replace function, it updates correctly.
The data type of the column is longtext:
# Field, Type, Null, Key, Default, Extra
'myColumn', 'longtext', 'NO', '', NULL, ''
The value in this column is metadata, that is a very long string of characters/code. In the middle is my url that I need to update.
Example: a:4:{s:5:"child";a:1:{s:0:"";a:1:{s:3:"rss";a:1:{i:0;a:6:{s:4:"data";s:3:" and on and on and on.
Additionally, if I just select with the REPLACE() function, it returns the correct value.
Is there an issue with having a forward-slash ("/") in the replace function or update statement?
Thanks
-M
I just changed the default value of a column in my database (w/ HeidiSQL) from NULL to -1, then I wanted to update every records that has a NULL value on this column to -1 but my query does not work :
UPDATE candidature
SET reponse_Manager = -1
WHERE reponse_Manager IS NULL
It actually runs without errors but doesn't find any NULL cells even though there are plenty. Any idea ?
I ended up changing values manually for every records with HeidiSQL
I have installed recently MySQL 5.7 . Something weird is happening with a date column.
If I execute a SELECT query using that field in a WHERE section, I have a resultset, but when I use the same WHERE condition to UPDATE a row I get an Invalid date format error message.
Here is the SELECT sentence:
SELECT *
FROM
FDpoCargTran
WHERE FDpoCargTran.Banco = '001'
AND (FDpoCargTran.Conciliacion = '' OR FDpoCargTran.Conciliacion IS NULL)
AND FDpoCargTran.Fecha = '2016-09-27'
This sentence returns 2 rows resultset, that's ok.
Now, Here's the UPDATE sentence:
UPDATE
FDpoCargTran
SET
Edo = 'C'
WHERE FDpoCargTran.Banco = '001'
AND (FDpoCargTran.Conciliacion = '' OR FDpoCargTran.Conciliacion IS NULL)
AND FDpoCargTran.Fecha = '2016-09-27'
AND Deposito = 1041
And I get this error message:
Data truncation: Incorrect date value: '' for column 'Conciliacion'
The Conciliacion columns is defined as:
`Conciliacion` date DEFAULT NULL,
If I remove the Conciliacion = '' condition, everything works fine.
Why empty string is not valid to evaluate the column in an UPDATE sentence and not in a SELECT?
Please, an idea!!!
Basically, for date datatype, you cannot store something like White
Spaces or ' ' strings. You need to make the column to accept NULL
values and insert an actual NULL into it. This is not a problem in MySQL 5.7, its how date is set in databases.
Update is a DML statement, when you actually want to write something into table, or check for a condition, MySQL is unable to understand what ' ' is for the date column type.
So, you cannot have ' ', instead you can have NULL set. Thats how MySQL can check the condition and make appropriate changes!!
I would suggest, change it to NULL.
Alter your datetime column to varchar.
Import whatever table/database.
Update FDpoCargTran set Conciliacion=NULL where Conciliacion='';
Alter column back to datetime.
I am using wamp in win 7.
In my database, I have one table be_users, two fields: username and email, both of them are set NOT NULL.
But why I still can insert empty value and null value into field: email, see below image:
Actually, you are inserting text and they are not NULL. The text NULL is very different from NULL. You can never violate the rule if the field is set to NOT NULL.
Try executing this statement,
INSERT INTO tableName VALUES (null, null) -- will fail
it will surely fail because those are NULL. But this statement below will surely work because you are inserting string.
INSERT INTO tableName VALUES ('', 'null') -- will work
An empty value does not equal NULL, and it looks like you are inserting 'null' not NULL into the database, so you are ending up with a string 'null' not a NULL value.
Dont send NULL enclosed with quotes 'NULL' or "NULL" its getting treated as text value.
the issue is due to the data type used for thease two field. "text" you can change this to varchar(255) to use NULL. There are some issue with NULL and data type text.
Null is a keyword. If you will enter null directly then it will show you error.
Example-
insert into tablename(fieldname) values(null);
This above line will generate error(if you have mentioned not null).
I think you have enter something else. Please check again the table structure and enter new data.
I have wrriten a vbs macro to automatically insert values from a DDE Excel sheet to a DB table.
The problem, is that some of the cells are empty
so the query turns out :
INSERT INTO `stock_realtime` (`fkstock`, `benefit_month`)
VALUES (77, '')
ON DUPLICATE KEY UPDATE `benefit_month` = '', `created` = NOW();
But my sql table contains default values of '0' just for cases like this when the value is empty.
Still it errors Incorrect integer value:'' for column 'benefit_month' at row 1'
The other (full) queries work fine.
'' is NOT empty (numeric) value, NULL is.
You are explicitly setting a value for benefit_month. If you don't set a value for a field then the default value will be set.
That would set the default value for benefit_month:
INSERT INTO `stock_realtime` (`fkstock`)
VALUES (77)