mysql – php insert / update one column-ThrowExceptions

Exception or error:

I want to insert data into department column because it only has Null values so I created Variable called $department grabbing correct data but I don’t want to affected the other columns they already have correct data.

users

UserID , first name  , last name , department

right now not sure what am doing wrong. this is what i have tried.

UPDATE Users SET department= '$department'";

INSERT INTO Users (department) VALUES (‘$department’);

thanks!

How to solve:

but I don’t want to affected the other columns they already have correct data.

So filter out the rows you don’t want to update:

UPDATE Users SET department= '$department'" WHERE department IS NOT NULL;

Answer´╝Ü

UPDATE Users SET department = '$department' WHERE department IS NULL;

This query put your correct value on each record that department field is null.

Leave a Reply

Your email address will not be published. Required fields are marked *