Danilkalmykov Danilkalmykov - 1 year ago 124
MySQL Question

Assigning the value to an empty field

Need to update a field in database, but when I make a request, it writes me "0 rows affected" although the image field is, and it is empty.

UPDATE `oc_product` SET `image`= 'no_image.png' WHERE `image`='';

Answer Source

Your query is checking for a value of an empty string, although from what you have shown the value you are actually looking to change has a value of NULL. These are two different values, NULL isn't equal to ''. As such if you are looking to replace items that have a NULL value you need to change your where statement for that (WHERE image IS NULL):

UPDATE `oc_product` SET `image`= 'no_image.png' WHERE `image` IS NULL;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download