Table:Person
+------+-------+
| name | age |
+------+-------+
| abc | NULL |
+------+-------+
I want to update age
in two conditions
- If age in the table is
NULL
, set it to the var$year
- If age in the table is NOT
NULL
, increase it by$year
I have the following code. But it does not update my age in table. What am I doing wrong?
$sql = "UPDATE `Person`
SET age =
CASE
WHEN age == null THEN $year
ELSE age + $year
END
WHERE name='abc'";
mysqli_query($conn, $sql);