We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,578 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Array Help

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.

3
Contributors
3
Replies
1 Hour
Discussion Span
5 Years Ago
Last Updated
4
Views
tie372
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

johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
Skill Endorsements: 0

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

vssp
Junior Poster
199 posts since Jul 2006
Reputation Points: 5
Solved Threads: 5
Skill Endorsements: 0

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

johnsquibb
Junior Poster in Training
84 posts since Nov 2007
Reputation Points: 14
Solved Threads: 14
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0668 seconds using 2.74MB