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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.