gevo12321 Posted June 27, 2007 Share Posted June 27, 2007 if the input is a check box, how would i set it up with the database so that it remembers if a box was checked or not Link to comment https://forums.phpfreaks.com/topic/57478-checkboxes/ Share on other sites More sharing options...
The Little Guy Posted June 27, 2007 Share Posted June 27, 2007 The HTML <input type="checkbox" name="cat" value="small"> The PHP <?php if(isset($_POST['cat']){ echo 'Checkbox cat was checked'; } ?> Link to comment https://forums.phpfreaks.com/topic/57478-checkboxes/#findComment-284394 Share on other sites More sharing options...
gevo12321 Posted June 27, 2007 Author Share Posted June 27, 2007 ya but lets say i want to open the page some time, and i want to see that the checkbox is checked. how do i store the info in a database saying that checkbox number 5 was checked last time the form was edited Link to comment https://forums.phpfreaks.com/topic/57478-checkboxes/#findComment-284396 Share on other sites More sharing options...
JasonLewis Posted June 28, 2007 Share Posted June 28, 2007 store the value in the database as something like, 0 = not checked and 1 = checked or something. then when you access page get the data from the table and run the checking. eg: $checkbox_5 = mysql_result(mysql_query("SELECT `checkbox_5` FROM `table`"), 0); if($checkbox_5 == 0){ $checked_5 = ""; }else{ $checked_5 = "checked='checked'"; } echo <<<html <input type="checkbox" name="box5" value="cat" {$checked_5}> html; there is one way of doing it, but if you have lots of checkboxes it may get annoying adding them all in. Link to comment https://forums.phpfreaks.com/topic/57478-checkboxes/#findComment-284550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.