[SOLVED] Multi-Select Values

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] Multi-Select Values

Post 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);
Last edited by $var on Tue Apr 04, 2006 8:13 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

change the name to cc[]
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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'
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the select tag's name. Then print_r($_POST['cc']) to see the selections.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post 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.
Post Reply