Jump to content

For each error


Drewser33

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/279759-for-each-error/#findComment-1438814
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/279759-for-each-error/#findComment-1438815
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/279759-for-each-error/#findComment-1438816
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.