开发者

syntax for inserting checkbox data from php page to database

I have a php form with some text box, list of radio buttons and che开发者_高级运维ckboxes with a submit button. I want to enter the values inputted in this php form to a database.The textbox as well as the radiobutton values and only one of my checkbox values are geting entered.I have a single column for entering the checkbox values in my query.I would like to know the syntax for entering all the selected checkbox values into that single column separated by commas.


Something like this will work. A name with "[]" at the end of it will return an array to $_POST. Should be ok with some testing.

HTML

<!-- open method="post" form here -->
<input type="checkbox" name="checkbox_name[]" value="1" />
<input type="checkbox" name="checkbox_name[]" value="2" />

PHP

<?php

// INSERT THIS VALUE INTO COLUMN FOR A COMMA DELIMITED LIST
$checkbox_values = implode(',', $_POST['checkbox_name']);

?>

Edit: You'll need to test for the array though, as if no boxes are checked, $_POST['checkbox_name'] will not be an array.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜