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

Recommended Answers

All 3 Replies

hi
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


Thanks

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

<?php
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')
}
?>

thank you for the solution.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.