0

I have a checkbox in PHP and I would like to have it checked if the value of the checkbox in the database is 1 and insert "0" in the database if saved and not checked

sample checkbox

  <input type="checkbox" name="chckpagibigcon" <?php 
            if(isset($_POST['chckpagibigcon'])){
                echo 'checked value = "0"';
            }else{
                echo 'value = "1"';
            }
            ?>>
Pang
  • 9,564
  • 146
  • 81
  • 122

2 Answers2

1

Pretty good solution would be:

<input type='hidden' name='chckpagibigcon' value='0'/>
<input type='checkbox' name='chckpagibigcon' value='1' <?php echo (isset($_POST['chckpagibigcon']))?'checked':'';?>/>
Michał Fraś
  • 407
  • 7
  • 12
0

Try this one:

<input type="checkbox" name="chckpagibigcon" <?php 
                                if(isset($_POST['chckpagibigcon'])){
                                    echo 'checked value = "1"';
                                }else{
                                    echo 'value = "0"';
                                }
                                ?>>

Just revers your condition.

Jitendra Yadav
  • 896
  • 1
  • 6
  • 14