dreampho Posted May 4, 2011 Share Posted May 4, 2011 Hi All!! I am a little confused. I have a form where I want around 15 different checkboxes, all or some of these can be checked. When the form is sent I insert the fields into a database. I am wondering how I can have only the fields checked saved into the database, without having to have a row for each field. Thanks Chris Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/ Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 you would probably make a field for each button that you have, and when the value of a certain button is passed, save that one, or those, into your db using one row Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/#findComment-1210423 Share on other sites More sharing options...
dreampho Posted May 4, 2011 Author Share Posted May 4, 2011 Sorry I am a bit confused. Say I have three checkboxes, if I do this: <?php try{ $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION; $database = new PDO('mysql:host=localhost;dbname=db', 'username', 'password', $pdo_options); $execution=$database->prepare('INSERT INTO db(checkbox1, checkbox2, choeckbox3) VALUES(:checkbox1, :checkbox2, :checkbox3)'); $execution->execute(array('checkbox1' => $_POST['Checkbox1'], 'checkbox2' => $_POST['Checkbox2'], 'checkbox3' => $_POST['Checkbox3'])); <? I would have to have a separate row for each checkbox in the database wouldnt I? Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/#findComment-1210450 Share on other sites More sharing options...
dreampho Posted May 4, 2011 Author Share Posted May 4, 2011 Sorry, I meant column Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/#findComment-1210456 Share on other sites More sharing options...
fugix Posted May 4, 2011 Share Posted May 4, 2011 yes that is what I was talking about Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/#findComment-1210458 Share on other sites More sharing options...
dreampho Posted May 4, 2011 Author Share Posted May 4, 2011 Sorry, I am confusing myself here. What I was hoping was there was someway to only save the results that were checked in the same column, rather than have 15 columns. Any ideas? Link to comment https://forums.phpfreaks.com/topic/235516-using-multiple-checkboxes/#findComment-1210460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.