Hello,
I was wondering if you’d be able to help with this, I am having trouble updating my database.
I only want to update the CarBrand and CarName columns for the relevant row (via IP match) when either of these columns is empty.
Please can you tell me if there are any errors with this syntax?
[php]
$sql = “UPDATE my_table SET
CASE
WHEN CarBrand = ‘’ THEN :carbrand
WHEN CarName = ‘’ THEN :carname
END
DateTime= :date,
Viewed = :viewed
WHERE IP = :ip”;
$stmt = $database->prepare($sql);
$stmt->bindParam(":carbrand", $CarBrand, PDO::PARAM_STR);
$stmt->bindParam(":carname", $CarName, PDO::PARAM_STR);
$stmt->bindParam(":date", $date, PDO::PARAM_STR);
$stmt->bindValue(":viewed", “1”, PDO::PARAM_INT);
$stmt->bindParam(":ip", $ip, PDO::PARAM_STR);
$stmt->execute();
[/php]