在复选框中回显数据库值

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'");

I think you have set your value to 1 (always) and I see checked on your html above

Try this!

<input type="checkbox" 
    value="<?php echo (isset($live))?$live:'1';  ?>" 
    name="live" data-on-color="warning"  
    <?php echo (isset($live) && $live == '1' )? 'checked="checked"':''; ?>
>