qwerty234 Posted April 13, 2007 Share Posted April 13, 2007 Hi, In my HTTP header I've collected the following values from a multi-select list after my POST: project_list=community_name&project_list=project_number&project_list=map_letter&project_list=home_type Here's my PHP code to loop thru the project_list after the POST. For some reason my array $a is not being populated, do you see why? $a = array(); foreach ($_POST['project_list'] as $selected) { if ($selected == 'community_name'){ $a[] = "projects.project_name "; } if ($selected == 'project_number'){ $a[] = "projects.project_number "; } if ($selected == 'map_letter'){ $a[] = "projects.map_letter "; } if ($selected == 'home_type'){ $a[] = "home_types.home_type "; } . . . Quote Link to comment Share on other sites More sharing options...
Guest prozente Posted April 13, 2007 Share Posted April 13, 2007 If I understand what you're trying to do correctly then put in your code echo '<pre>' print_r ($_POST); echo '</pre>'; then submit the form and look at the results. I'm guessing you didn't set the input tags as an array in the html. Also a switch would be better instead of all of those if statements since you are only looking at a single variable. Quote Link to comment Share on other sites More sharing options...
HeyRay2 Posted April 13, 2007 Share Posted April 13, 2007 I see two things wrong with the following line based on what I'm reading: project_list=community_name&project_list=project_number&project_list=map_letter&project_list=home_type If this is what you're seeing in the URL after you submit your form, then you are passing your form variables using the $_GET array, not the $_POST array. Change your form submit method to "POST" if you are not already. Additionally, if you're trying to pass a multi select list from an HTML form, you have to append brackets to the end of the form element name. So instead of using "project_list" for the name, you would need to use "project_list[]". Otherwide, each time a"project_list" value was defined, it would overwrite the existing value because the value is being treated as a string. If you use "project_list[]", then each new definition will add an element to the array, as the values would be treated as array elements. Good luck! Quote Link to comment 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.