How to insert multiple check-box values inside database when one or more will be left unchecked?

Posted by Sally on Stack Overflow See other posts from Stack Overflow or by Sally
Published on 2010-03-17T06:45:04Z Indexed on 2010/03/17 6:51 UTC
Read the original article Hit count: 255

Filed under:
|
|

I have a form that contains 5 check boxes. The user may select one or more of these check boxes. The user may select 2 and leave 3 unchecked or select 4 and leave one unchecked and so on, in that case how can I write the php/mysql code that will insert the form data into the database. With just one selection it's easy, I would do:

$checkbox_value = $_POST['i_agree'];

mysql_query("INSERT INTO terms (user, pass, conditions) VALUES ('$user','$pass','$checkbox_value')");

But how can I write this when there are multiple check box options and only one or more of them will be checked?

I want to insert them all in one column called "tags" separated by commas.

© Stack Overflow or respective owner

Related posts about php

Related posts about forms