Welcome Guest, Not a member yet? Register   Sign In
How to insert the values from each checked checkboxes into the database
#11

[eluser]CroNiX[/eluser]
The answer really depends on how you're doing it, as there are many.

What does your form look like where these checkboxes are?
#12

[eluser]towki[/eluser]
Code:
<?php echo form_open('crimeIndex/add') ?>

<strong>Crimes Vs. Persons</strong>
<br/ >&lt;input type="checkbox" name="offense[]"  value="Murder" /&gt;Murder
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Homicide" /&gt;Homicide
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Parricide/Infanticide" /&gt;Parricide/Infanticide
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Physical Injuries" /&gt;Physical Injuries
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Maltreatment" /&gt;Maltreatment
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Kidnapping" /&gt;Kidnapping<br/ >

     <strong>Crimes Vs. Property</strong>
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Robbery" /&gt;Robbery
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Theft" /&gt;Theft
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Estafa & Falsification" /&gt;Estafa & Falsification
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Malicious Mischief" /&gt;Malicious Mischief
     <br/ >&lt;input type="checkbox" name="offense[]"  value="Damage to Property" /&gt;Damage to Property
     </div>

&lt;/form&gt;

This is only a part of my form , all name of the checkboxes are similar based on what @xeroblast said. I hope i did it right :lol:

I can undestand a bit of @xeroblast code. The things that confuses me were the "dots" in some part of the code and also the delimiter thing.
#13

[eluser]CroNiX[/eluser]
How are you storing these values in the database?
#14

[eluser]CroNiX[/eluser]
Code:
//Will only show checked box values
foreach($this->input->post('offense') as $cb_value)
{
  echo $cb_value . '<br>';
}

If you want to know what was checked AND unchecked, you could create an array of all possible values and check against that.

Code:
$offences = array(
  'Homicide',
  'Parricide/Infanticide',
  //etc
);

foreach($this->input->post('offense') as $value)
{
  $checked = in_array($value, $offences);//will be boolean TRUE/FALSE
  echo "'$value' was ";
  echo ($checked) ? '' : 'NOT';
  echo ' checked<br>';
}


Code:
//comma separated checked values
$checkboxes = $this->input->post('offense');
$checked = ($checkboxes !== FALSE) ? implode(',', $checkboxes) : '';
There are lots of ways to do this, but it really depends on how you are storing the data.




Theme © iAndrew 2016 - Forum software by © MyBB