1,105,556 Community 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.

Member Avatar
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 3 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
vssp
Junior Poster
197 posts since Jul 2006
Reputation Points: -5 [?]
Q&As Helped to Solve: 5 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 3 [?]
Q&As Helped to Solve: 14 [?]
Skill Endorsements: 0 [?]
 
0
 

here's a sample of that in action...
http://70.180.184.28/chkt.php

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