Start New Discussion within our Web Development Community

I have a bunch of checkboxes on one page, that look like this

<input type="checkbox" value="classic" name=subgenre[]></input>

And when all the data is collected and inserted into a databse, it looks like this


This is supposed to collect every box that is checked and store it in a database in a basic list, however I can not get it to work, and arrays are not my strongpoint. Any help is appreciated.

Deleted Member

You could try using a foreach loop to cycle through each $_POST...if you begin the name of your checkbox elements with something like 'chk_', it would be easy to filter them out from all the other form elements by using a substring search... <input type="checkbox" value="checked" name=chk_nameHere></input>

foreach ($_POST as $key => $value) 
	if(substr($key, 0, 4) == 'chk_')
		//only checked checkboxes will post...
		echo $key.' was checked!';


hope that gives you a start

using implode function to get all the values to one single variable separated by comma . then easy to inser the values to table

This article has been dead for over six months. Start a new discussion instead.