beginner PHP programmer here trying to use the mailchimp API…
I keep getting this PHP error with regard to my first line of code here…. I am posting a value from a form, as you can see, but I am not sure what is going on.
The error:
Warning: Variable passed to each() is not an array or object in xxxxxxx on line 24 (which is the first line)
while (list($key, $val) = each($_POST['MCgroup'])) {
$interest .= ($count>0 ? ", " : "");
$interest .= $val;
$count++;
}
echo $interest; //echos NOTHINGblank
$mergeVars = array(
'INTERESTS'=>$interest
);
echo $mergeVars; //echos the word ARRAY
From what I have researched, OBVIOUSLY I am not passing an actual ARRAY… but also from what I have found, my syntax all seems correct. (But I could be overlooking something).
Here is the part of the form code that is passing the values
<input type="hidden" name="MCgroup" id="MCgroup" value="My Interest One" />
<input type="hidden" name="MCgroup" id="MCgroup" value="My Interest Two" />
or I COULD change it to
<input type="hidden" name="MCgroup" id="MCgroup" value="My Interest One, My Interest Two" />
I just am not sure how to make THAT into an array.
Help please! Thanks!
You can set your
<input>to have an array name by suffixing[], do something like this:<input type="hidden" name="MCgroup[]" id="MCgroup" value="My Interest One" /><input type="hidden" name="MCgroup[]" id="MCgroup" value="My Interest Two" />then check it by:
print_r($_POST['MCgroup']);Where I assume you set form method to POST.