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 Quote Link to comment 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'; } ?> Quote Link to comment 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 Quote Link to comment 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. 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.