xprt007 Posted March 1, 2006 Share Posted March 1, 2006 Hi,I need some help urgently.[code]<td nowrap colspan="3"> Smoker: <input type="checkbox" name="Eigenschaften[]" value="smoker" class="check"> Formular1 Fan: <input type="checkbox" name="Eigenschaften[]" value="f1fan" class="check"> Soccer Fan: <input type="checkbox" name="Eigenschaften[]" value="soccerfan" class="check"> Womanizer: <input type="checkbox" name="Eigenschaften[]" value="womanizer" class="check">[/code]I want to get that input into a database. The problem is when I do it the normal way, ie$Eigenschaften = $_POST['Eigenschaften'] before entering it into database, I get the entry "array" in database. I must say I added the [] beside the variable name, after I was told arrays need to be used if more than one entry is automatically selected, even if one ticked more than one checkbox. That means I was always getting one entry into database.After endless googling, I have established one has got to use some form of arrays. There so many different suggestions, but none has led me to the desired result.An example:[code] if ($_POST['Eigenschaften']) { foreach($_POST['Eigenschaften'] as $element) { echo "$element"; } }[/code]That echos the entries I want. [!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--][Result after checking all the 4 boxes ==> smokerf1fansoccerfanwomanizer] [!--colorc--][/span][!--/colorc--] The problem is as soon as u replace say echo = "$element"; with say $varA = "$element"; to try & create a variable out of it, .. if one tries to enter it into database or echo it, it only returns one entry from the checkbox.The many examples I have seen after googling dozens of sites, only "echo" the result. I dont want that. I want all the checked entries together possibly stored in one variable like $varA ... that I can use for different things, before entering them in database.Does any one have an idea how to get the problem solved? Link to comment https://forums.phpfreaks.com/topic/3834-how-do-i-get-multiple-checkbox-content/ Share on other sites More sharing options...
shocker-z Posted March 1, 2006 Share Posted March 1, 2006 Try this..if ($_POST['Eigenschaften']) { foreach($_POST['Eigenschaften'] as $element) { $varA = $varA."$element "; }}Else you could use$varA=join (', ', $_POST['Eigenschaften']);Which would do the same thing but proberly the better way.. Link to comment https://forums.phpfreaks.com/topic/3834-how-do-i-get-multiple-checkbox-content/#findComment-13317 Share on other sites More sharing options...
xprt007 Posted March 1, 2006 Author Share Posted March 1, 2006 Thanks a great deal. In spite of making endless searches (googling on many PHP related sites) I'd not (yet) come across something like that. May be I have not been looking in the right places. Link to comment https://forums.phpfreaks.com/topic/3834-how-do-i-get-multiple-checkbox-content/#findComment-13350 Share on other sites More sharing options...
Recommended Posts