user1679009
user1679009

Reputation: 51

php insert / update one column

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!

Upvotes: 1

Views: 279

Answers (2)

user7013467
user7013467

Reputation:

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

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

Upvotes: 0

GMB
GMB

Reputation: 222512

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;

Upvotes: 1

Related Questions