Multiple values from listbox to form email

Hello,

I know very little PHP. I appreciate any help you can offer for what will probably be (hopefully) a simple question/solution. :smiley:

I am using PHP to email data collected from a form. I have added a list box in the form that allows the buyer to select more than one value. Using the code snippets below, I can’t seem to get the values to be displayed in the email message. I do see a separate line for each value selcted when the info is emailed, but instead of seeing the name of the value, it’s empty. What am I doing wrong?

[code]

Peppermint Cinnamon Spearmint Wintergreen

[/code]
[php]<?

@$Flavor= $_POST[ā€˜Flavor’];
if( is_array($Flavor)){
while (list ($key, $val) = each ($Flavor)) {[/php]$msg .= ā€œFlavor: \t$_POST[$val]\nā€;
}
}
?>

Your problem is here:

[php]$_POST[$val][/php]

You are looking for the value in the $_POST array, for example $_POST[ā€˜Cinnamon’] doesn’t exist.

If you wanted to access this value you would need to specify $key not $val. You are also accessing the $_POST array instead of $Flavor so you would need to specify the ā€˜Flavor’ key as well.

For example:

[php]
// this would work accessing the $_POST array
$msg .= ā€œFlavor:\tā€ . $_POST[ā€˜Flavor’][$key] . ā€œ\nā€;

// this would also work accessing the $Flavor array
$msg .= ā€œFlavor:\tā€ . $Flavor[$key] . ā€œ\nā€;

// this is most likely what you should be using since you have no need to access the arrays directly
$msg .= ā€œFlavor:\tā€ . $val . ā€œ\nā€;
[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service