1.11M Members

Array Help

tie372
Deleted Member
 
0
 

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.

 
0
 

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

 
0
 

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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article