houssam_ballout Posted July 4, 2007 Share Posted July 4, 2007 Hello all,I am building an application (web),and I am designing a form,using HTML, I'd checkboxes , I am using isset to enter the data into the database, how can I know if the user has checked or not the checkbox (using checked property), how would I enter that into database?>I am using the type of that field as binary?is that correctThanks in advance Link to comment Share on other sites More sharing options...
justsomeguy Posted July 5, 2007 Share Posted July 5, 2007 If the field can either be a 1 or 0, binary would probably work, I typically use tinyint. if (isset($_POST['checkbox_name'])) $checkbox_value = 1;else $checkbox_value = 0;//or$checkbox_value = (isset($_POST['checkbox_name']) ? 1 : 0); Link to comment Share on other sites More sharing options...
houssam_ballout Posted July 6, 2007 Author Share Posted July 6, 2007 USing Mysql, Wat type of that entry should be in the database?Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2007 Share Posted July 6, 2007 If the field can either be a 1 or 0, binary would probably work, I typically use tinyint. Link to comment Share on other sites More sharing options...
houssam_ballout Posted July 6, 2007 Author Share Posted July 6, 2007 Well, I used the binary, but when I look at the results of the inserting, I see something like \A..Did the tinyint worked well with u ?Also, in the html how could I enter that fact into the database?thanks in advace Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2007 Share Posted July 6, 2007 I always use tinyint, it works fine. You can also reduce the field size from the default 4 down to 1 to conserve a little space. Also, in the html how could I enter that fact into the database?I don't know what you mean by that. Link to comment Share on other sites More sharing options...
houssam_ballout Posted July 6, 2007 Author Share Posted July 6, 2007 Should I use isset, to see if the checkbox is checked or not? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2007 Share Posted July 6, 2007 Either use isset, or give the checkbox a value and check for the value.<input type="checkbox" name="box1" value="1" />if ($_POST['box1'] == "1") Link to comment Share on other sites More sharing options...
houssam_ballout Posted July 6, 2007 Author Share Posted July 6, 2007 Ok thanks alot One more question: I'd a form with many check boxes and submit button, I use isset($_POST['submit']))how could I insert all the checkboxes in that statment? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 6, 2007 Share Posted July 6, 2007 You need to check for each box and build a SQL statement to include those boxes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.