0

i have a html form that has a more then 30 checkboxes. checkboxes are used to select for different service.

I want to store those all value in 1 Database field seperated by , those could be numeric or string. Code for inserting checkbox values is as follows:

 <form method="post" action="posted.php">
    Option 1: <input type="checkbox" name="type" value="1" /><br />
    Option 2: <input type="checkbox" name="type" value="2" /><br />
    Option 3: <input type="checkbox" name="type" value="3" /><br />
    Option 4: <input type="checkbox" name="type" value="4" /><br />
    Option 5: <input type="checkbox" name="type" value="5" /><br />
    Option 6: <input type="checkbox" name="type" value="6" /><br />
    Option 7: <input type="checkbox" name="type" value="7" /><br />
    Option 8: <input type="checkbox" name="type" value="8" /><br />
    Option 9: <input type="checkbox" name="type" value="9"/><br />
    <input type="submit" value="Submit" />
 </form>

After successful submission off course i need to fetch those data in the corespondent check box while update.

Please response me as soon as possible with complete PHP code.

1 Answer 1

1

You can use JSON. From this:

Option 1: <input type="checkbox" name="myval[option_name1]" /><br />
Option N: <input type="checkbox" name="myval[option_nameN]" /><br />

Store:

$model->field = json_encode($_POST['myval']);

Or comma-seporated (if you really want):

$model->field = implode(",", $_POST['myval']);
Sign up to request clarification or add additional context in comments.

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.