laflair13 Posted March 6, 2015 Share Posted March 6, 2015 Sorry guys but I am back with another question. I have tried quite a few different ways and I cannot seem to get this to work. I have checkboxes being stored as 1=checked, 0=not check but when I go to the item page the checkbox isnt checked. Here are some codes that I have tried <input type="checkbox" name="featured" <?php if ($featured == '1') echo "checked='checked'"; ?> class="form-control" /> <input type="checkbox" name="featured" <?php if($var) { echo 'value="checked"'; }?> class="form-control" /> <input type="checkbox" name="featured" value="1" <?php echo ($row1['featured'] == 1) ? 'checked="checked"' : ''; ?> class="form-control" /> (This shows it checked even when its not) Any help would be appreciated. Quote Link to comment Share on other sites More sharing options...
laflair13 Posted March 6, 2015 Author Share Posted March 6, 2015 (edited) Well I was able to get that working but now if I edit the item and uncheck the box, it does not change the value in the database from 1 to 0. input for 1 of the checkboxes. I have 10 of them <input type="checkbox" name="showmodel" <?php if ($showmodel == '1') echo "checked='checked'"; ?> /> Here is my update query $query = "UPDATE `new_equip` SET `featured`='1',`showmanu`='1',`showmodel`='1' "WHERE `id`='$id' LIMIT 1"; Edited March 6, 2015 by laflair13 Quote Link to comment Share on other sites More sharing options...
Barand Posted March 6, 2015 Share Posted March 6, 2015 I suggest you re-read a reply I sent to you yesterday http://forums.phpfreaks.com/topic/295128-mysqli-update-not-working/?do=findComment&comment=1507666 Quote Link to comment Share on other sites More sharing options...
CroNiX Posted March 7, 2015 Share Posted March 7, 2015 To build on what Barand is saying, checkboxes that are not checked do not get sent in a GET/POST request. Only checked checkboxes (and radio selectors). So you need to check to see if it exists in POST/GET, if it does not, set a value like 0 before saving in the database. See Barands link above for an example. Quote Link to comment Share on other sites More sharing options...
CroNiX Posted March 7, 2015 Share Posted March 7, 2015 Also, read up on "successful form controls" for the official explanation in the HTML specs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.