Member Avatar for tie372

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

$subgenre=$_POST[subgenre];

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.

Recommended Answers

All 3 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.