I'm trying to be lazy (or smart): I have 7 checkboxes that correlate with 7 columns in a MySQL table.
Flags are placed in an array:
$can = $_POST['can'];
I created the following loop to dump variables for inserting MySQL:
for($i=1;$i<8;$i++){ if($can[$i] == "on"){ ${"jto_can".$i} = 'Y'; } else{ ${"jto_can".$i} = 'N'; } } print_r($jto_can1.$jto_can2.$jto_can3.$jto_can4.$jto_can5.$jto_can6.$jto_can7);
This correctly outputs:
YYNYYYY
However, when I try to use these variables in my MySQL update, it does not accept the changes.
mysqli_query($db, "UPDATE jto SET jto_can1 = '$jto_can1', jto_can2 = '$jto_can2', jto_can3 = '$jto_can3', jto_can4 = '$jto_can4', jto_can5 = '$jto_can5', jto_can6 = '$jto_can6', jto_can7 = '$jto_can7' WHERE jto_id = '$id'")or die(mysqli_error($db));
Can someone explain why print_r displays variables while MySQL update is not working?
source share