i have four checkboxes, user have option to select all or any of them as per the nature of complaint. the html code is as follow....

<input type="checkbox" name="comp1" value="Abusive words are used">
<input type="checkbox" name="comp2" value="Attachments are vulgar">
<input type="checkbox" name="comp3" value="Provided links are not valid or open fake website">
<input type="checkbox" name="comp4" value="Provided contents are fake">

now, i want to know which option has been selected by the user, because accordingly i put the option sequence in one column of mysql. i want to store only the values which are not empty or only selected by the user....

any help please that how can it be done in php....

7 Years
Discussion Span
Last Post by servis

you can give the same name for all check box as per i given here in example

<input type="checkbox" name="comp[]" value="Abusive words are used">
<input type="checkbox" name="comp[]" value="Attachments are vulgar">
<input type="checkbox" name="comp[]" value="Provided links are not valid or open fake website">
<input type="checkbox" name="comp[]" value="Provided contents are fake">

Now you get this value in array which selected by user

$values=$_post['comp'];//$values is an array of selected value by user

Now if you want to find that which value is selected than you can use na is_array() function ok



And, to process Tulsa's values, I recommend looking into the implode function.

if(isset($_POST['comp'])) {
  // Clean data
  $cleanData = array();
  foreach($_POST['comp'] as $_comp) {
    $cleanData = mysql_real_escape_query($_comp);

  // Build query
  $compStr = implode("'), ('", $cleanData);
  $sql = "INSERT INTO tbl('compCol') VALUES('$compStr')";

  // Example query:
  //  INSERT INTO tbl('compCol') VALUES('first'), ('second'), ('third')
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.