0

I want to store the multiple checkbox values to store in a single field. I use that link http://www.mindfiresolutions.com/Storing-array-data-to-MySQL-using-PHP-1296.php. But i dont get the result.Give Help to find that problem.

9
  • 1
    What result do you get? Commented Dec 26, 2012 at 10:23
  • what result is getting inserted? Commented Dec 26, 2012 at 10:24
  • Can you post your code so we that we can check where's the problem? Commented Dec 26, 2012 at 10:26
  • show us your checkbox code please Commented Dec 26, 2012 at 10:26
  • I want to display the selected checkbox values andall the values must be stored in the single field itself. Commented Dec 26, 2012 at 10:27

2 Answers 2

1

Set your column as 'set' (specify the all possible values.) data type and than run the below query.

$comma_separated = implode(",", $values);
$insert_query = "INSERT INTO TABLE_NAME(col_name) VALUES('$comma_separated')";
$result_insert = mysql_query($insert_query);

I hope this will solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

I hope this will helpful

<html>
<body>
<form action="" method="post">
<p><input type="checkbox" name="color[]" value="red" />Red</p>
<p><input type="checkbox" name="color[]" value="blue" />Blue</p>
<p><input type="checkbox" name="color[]" value="orange" />orange</p>
<input type="submit" value="submit" name="sub" />
</form>

<?php

if(isset($_POST['sub']))
{
    mysql_connect("localhost","root","") or die("Server Could not be connected");
    mysql_select_db("gobinath") or die("database connection problam");
    $color=implode(',',$_POST['color']);

    mysql_query("insert into mcheck values('','$color')") or die("insert problam");

}
?>
</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.