Page 1 of 1

[SOLVED] Multi-Select Values

Posted: Mon Apr 03, 2006 2:07 pm
by $var
Hi,

I am making a mail form with a the CC being selected from 'Multiple' select list, which, is being generated from a database using PHP.

The deal is, the echoed CC values, regardless of how many are selected returns only the 1 which is lowest on the list.

for example, if of:
1
2
3
4

I selected:
1
2
4

Then 4 would be the final value. Why would this be? Isn't that the point of the multi-select?
I can post the code if needed.

SELECT:

Code: Select all

<select name="cc" size="8" multiple="multiple">
		<option value="0">No Assignment</option>
      <option value="0">-------------</option>
      <? 
		$sql = "SELECT COUNT(*) FROM it_mem WHERE Mem_X=0 AND Mem_Level!='0'";
		$numrecord = mysql_query($sql);
		$numrecords = mysql_fetch_array($numrecord);
		
		$intRecsPerPage=100;
		if($_POST["intpage"]=="")
		{
			$intpage=1;
		}
		
			$sql2 = "SELECT * FROM it_mem WHERE Mem_X=0 AND Mem_Level!='0' ORDER BY Mem_LName";
			$resultassignment = mysql_query($sql2) or die (mysql_error());
			for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
			{
				if($x/2 != intval($x/2))
						{
							$bgcolor = "#ffffff";
						}
						else
						{
						$bgcolor = "#F7F7F7";
						}
				if($x >= $numrecords[0])
				{
					break;
				} // REPEAT IF MORE THAN ONE
				$assignmentresults = mysql_fetch_array($resultassignment);
					echo "<option value='$assignmentresults[Mem_Email]'>";
					echo "$assignmentresults[Mem_LName], $assignmentresults[Mem_FName] ";
					echo "</option>";
					 }?>
  </select>


MAIL FUNCTION:

Code: Select all

$cc=$_REQUEST["cc"];

Code: Select all

$address = $toEmail';
$subject = "RE:[Ticket: $issueID] $title";
$headers = 'From: admin@honeycombworldwide.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "Reply-To: admin@honeycombworldwide.com\r\n";
$headers .= "Return-Path: admin@honeycombworldwide.com\r\n";
$headers .= "CC: $cc.', ';
mail($address, $subject, $mail_body, $headers);

Posted: Mon Apr 03, 2006 2:12 pm
by feyd
change the name to cc[]

Posted: Mon Apr 03, 2006 2:27 pm
by $var
Like this?

Code: Select all

$headers .= "CC: $cc[] \r\n";
returns this error, am i using the wrong instance of cc?:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

Posted: Mon Apr 03, 2006 2:48 pm
by feyd
the select tag's name. Then print_r($_POST['cc']) to see the selections.

Posted: Mon Apr 03, 2006 4:41 pm
by $var
how do you echo out the array?

Code: Select all

$headers .= "CC: ".print_r($_POST["cc"])." \r\n";
= CC: 1

Code: Select all

$headers .= "CC: ".$_POST["cc"]." \r\n";
= CC: Array

Posted: Mon Apr 03, 2006 4:50 pm
by feyd
I meant to see it for yourself, not for use in the email. You can use a loop or implode() to make it a string, however you really should process the entries to make sure they are valid addresses and someone isn't trying to inject headers into your email.

Posted: Tue Apr 04, 2006 8:13 am
by $var
great, implode did it.

i knew that the print_r() was only for my viewing, but i didn't know about implode() and when i echoed just $cc it returned "Array".. i figured there was something.