My current code updates all values, and if there is an empty parameter it updates the corresponding field on the table to null. I want to update only the fields that have a value.
This is my code:
$sql = "
UPDATE drinks SET
name = :name, // Mojito -> Update it
description = :description, // Lorem ipsum.. -> Update it
glass_id = :glass_id, // NULL -> do not update
video_url = :video_url // NULL -> do not update
WHERE id = '$drinkId'
";
try {
$db = new db();
$db = $db->connect();
$stmt = $db->prepare($sql);
$stmt->bindParam(':name', $drinkName);
$stmt->bindParam(':description', $description);
$stmt->bindParam(':glass_id', $glassId);
$stmt->bindParam(':video_url', $videoUrl);
$stmt->execute();
// Close databse
$db = null;
} catch(PDOException $e) {
echo $e;
}