dimanche 15 mars 2015

Echoing database value in checkbox

I'm sure this has been asked a million times before but I can't find a clear answer anywhere. I'm using Bootstrap Switch. The switch is updating the database just fine but I want the switch to be in the OFF postion if $live='0' and in the ON position if $live = '1'. At the moment it just stays in the ON position regardless of what $live is. I just cant figure it out, I'd really appreciate any help.


The html



<input type="checkbox" value="1" name="live" checked data-on-color="warning" <?php if($live=='1'){echo 'CHECKED' ;} ?>>


And the php extract:



if( isset( $_POST['live']) )
{
$live = '1';
} else {
$live = '0';
}


And the final piece of abbreviated php:



$sql = ("UPDATE members SET `live` = '$live' WHERE `username` = '$username'");




Aucun commentaire:

Enregistrer un commentaire