Jump to content

Using multiple checkboxes


dreampho

Recommended Posts

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

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.