Something basic but I don’t see why it doesn’t work I want to save the state of a checkbox in a database, type Boolean, if checked 1 else 0 here is my code:
<input type="checkbox" name="stok" value="1" <?php if(isset($_POST['stok'])) echo "checked='checked'"; ?> /> <?php if (isset($_POST['stok']) && !empty($_POST['stok']) && $_POST['stok'] === 'on') $stok = 1; else $stok = 0; mysql_query ("update tab set etat_vendu=$stok where id=$big"); ?> //this is my var $stok=$row['stok'];
Answer
This will work:
if(isset($_POST['stok'])){ //$stok is checked and value = 1 $stok = $_POST['stok']; } else{ //$stok is nog checked and value=0 $stok=0; }