sh0wtym3 Posted July 22, 2009 Share Posted July 22, 2009 I have a small form with checkboxes, however when multiple checkboxes are selected, only the LAST one gets stored into the variable. Here is the form: <td> <input type="checkbox" name="prop[]" value="residential properties, "> Residential </td> <td> <input type="checkbox" name="prop[]" value="single family homes, "> Single Family </td> <td> <input type="checkbox" name="prop[]" value="multi-family homes, "> Multi Family </td> <td> <input type="checkbox" name="prop[]" value="commercial properties, "> Commercial </td> And here is the php that stores the variable: $prop = $_POST['prop']; My goal is to echo the variable, and have it produce the output: "residential properties, single family homes, multi-family homes, commercial properties, and more!" echo "$prop and more!"; Link to comment https://forums.phpfreaks.com/topic/166978-solved-combining-checkbox-values-into-single-variable/ Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 while(list($key,$val) = each($prop)){ echo "$val, "; } Link to comment https://forums.phpfreaks.com/topic/166978-solved-combining-checkbox-values-into-single-variable/#findComment-880356 Share on other sites More sharing options...
sh0wtym3 Posted July 22, 2009 Author Share Posted July 22, 2009 I'll try that now, but just curious, why are you using a variable named $key? Link to comment https://forums.phpfreaks.com/topic/166978-solved-combining-checkbox-values-into-single-variable/#findComment-880360 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 $prop = implode(', ', $_POST['prop']); Link to comment https://forums.phpfreaks.com/topic/166978-solved-combining-checkbox-values-into-single-variable/#findComment-880369 Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 I'll try that now, but just curious, why are you using a variable named $key? It's a value in each(). Link to comment https://forums.phpfreaks.com/topic/166978-solved-combining-checkbox-values-into-single-variable/#findComment-880383 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.