Drewser33 Posted July 1, 2013 Share Posted July 1, 2013 foreach($_POST['customerID'] as $value) Warning: Invalid argument supplied for foreach() I have used _GET as well, to confirm that there are values for this variable. What am I missing? Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 1, 2013 Share Posted July 1, 2013 What do you get with this var_dump($_POST['customerID']); Quote Link to comment Share on other sites More sharing options...
Drewser33 Posted July 1, 2013 Author Share Posted July 1, 2013 I get : string(2) "27" Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted July 1, 2013 Solution Share Posted July 1, 2013 OK, you can't do a foreach() loop on a string, which is why you are getting the error. Are you allowing the user to make multiple customerID selections/entries? Did you name the fields appropriately so it will be sent as an array? E.g. <input type="checkbox" name="customerID[]" value="33" /> Note the [] at the end of the input name Quote Link to comment Share on other sites More sharing options...
Drewser33 Posted July 1, 2013 Author Share Posted July 1, 2013 echo '<option value='.$row['ID'].'>'.$row['LastName'].', '. $row['FirstName'].'</option>'; This is part of a select box, so no, I did not have the []. I will use a checkbox instead, that will likely be a better type of input instead, and I will use the [] as you mention. Thank you. I will build the checkbox quickly and check it out. Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 1, 2013 Share Posted July 1, 2013 echo '<option value='.$row['ID'].'>'.$row['LastName'].', '. $row['FirstName'].'</option>'; This is part of a select box, so no, I did not have the []. I will use a checkbox instead, that will likely be a better type of input instead, and I will use the [] as you mention. Thank you. I will build the checkbox quickly and check it out. The same also holds for a select field that uses the multiselect parameter. You need to name the field with a [] at the end for the multiple values to be passed as an array. <select name="customerID[]"> Also, I prefer to use double quotes when defining strings with variables echo "<option value='{$row['ID']}'>{$row['LastName']}, {$row['FirstName']}</option>"; Whether you use a select list or a checkbox is a personal decision. I prefer using checkboxes since many users don't know how to make multiple selections in a select field. 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.