rooney Posted September 27, 2007 Share Posted September 27, 2007 I am using a php mysql database and have 3 checkboxes in my form. I have one column for each checkbox. I want that if a user checks a box, the value that goes into the corresponding colum should be 1 , else 0. The data type i selected for the column is BOOL. But how to accomplish the storing of data into the table ?. Been trying for long but no success. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/70830-solved-need-help-regarding-checkboxes/ Share on other sites More sharing options...
greenday Posted September 27, 2007 Share Posted September 27, 2007 I always use ENUM as the Type and '1','0' as the Length/Values. have 0 as the default. Then this on the sql insert: GetSQLValueString(isset($_POST['yourfieldname']) ? "true" : "", "defined","1","0"), Hope that helps? Quote Link to comment https://forums.phpfreaks.com/topic/70830-solved-need-help-regarding-checkboxes/#findComment-356225 Share on other sites More sharing options...
hemlata Posted September 27, 2007 Share Posted September 27, 2007 Hello, The below script can also solve your issue echo isset($_POST['checkbox_name'])? '1' : '0'; Regards, Quote Link to comment https://forums.phpfreaks.com/topic/70830-solved-need-help-regarding-checkboxes/#findComment-356229 Share on other sites More sharing options...
localhost1 Posted September 27, 2007 Share Posted September 27, 2007 u can try this way define the default database field value as 0 and from check box pass the value this way <input type="checkbox" name="name1" value="1" /> <input type="checkbox" name="name2" value="1" /> <input type="checkbox" name="name3" value="1" /> abnd write the sql query to insert the value of the checkbox when the it is checked Quote Link to comment https://forums.phpfreaks.com/topic/70830-solved-need-help-regarding-checkboxes/#findComment-356234 Share on other sites More sharing options...
rooney Posted September 27, 2007 Author Share Posted September 27, 2007 Thanks guys The problem got solved =) Quote Link to comment https://forums.phpfreaks.com/topic/70830-solved-need-help-regarding-checkboxes/#findComment-356348 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.