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!"; Quote 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, "; } Quote 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? Quote 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']); Quote 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(). Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.