So I might just be overlooking something stupid simple, but essentially I am trying to CASE the FIELD for an UPDATE in MySQL through a PHP page. I have run a ton of IF statements as well but cant seem to get this to work.
<?php
include('config.php');
$username = $_POST['username'];
$charName = $_POST['charName'];
//ID MARKS
$idMarks = $_POST['IDmarks'];
//EXPERIENCE
$EXP = $_POST['EXP'];
$sql = "UPDATE characters
SET CASE
WHEN idMarks1 IS NULL THEN idMarks1 = '$idMarks'
WHEN idMarks2 IS NULL THEN idMarks2 = '$idMarks'
WHEN idMarks3 IS NULL THEN idMarks3 = '$idMarks'
WHEN idMarks4 IS NULL THEN idMarks4 = '$idMarks'
WHEN idMarks5 IS NULL THEN idMarks5 = '$idMarks'
WHEN idMarks6 IS NULL THEN idMarks6 = '$idMarks'
WHEN idMarks7 IS NULL THEN idMarks7 = '$idMarks'
WHEN idMarks8 IS NULL THEN idMarks8 = '$idMarks'
WHEN idMarks9 IS NULL THEN idMarks9 = '$idMarks'
WHEN idMarks10 IS NULL THEN idMarks10 = '$idMarks'
WHEN idMarks11 IS NULL THEN idMarks11 = '$idMarks'
WHEN idMarks12 IS NULL THEN idMarks12 = '$idMarks'
END
totalEXP = totalEXP + '$EXP',
remEXP = remEXP + '$EXP'
WHERE charName = '$charName' AND username = '$username';
";
if ($conn->query($sql) === TRUE) {
header("Location: ../lead.php");
} else {
echo "Error updating record: " . $conn->error;
}
?>
The idea here is that the update will put the new value ($idMarks) in the first null value it finds and then roll on to the next EXP columns. I cant just use an array due to prior issues Ive had with MySQL, and the point is that the idMarks columns are kind of fluid, tracking wounds, wounds heal to scars or limps, tattoos are permanent, etc etc which is why they are adjustable on another page. Does anyone have any ideas on how to pull this off?