Re: Switch
- From: Csaba Gabor <csaba@xxxxxx>
- Date: Tue, 20 Nov 2007 02:20:31 +0100
Bill H wrote:
/* Initialize a clean array to replace $_POST with clean data */Isn't it simpler to do:
$etype = $_POST['etype'];
$errmsg = 'etype-: '.$etype.' | Case value-: ';
/* Define the mailto address
switch ($etype) {
case 0:
$mailto = 'sales@xxxxxxxxxx';
$errmsg .= '0';
break;
case 1:
$mailto = 'support@xxxxxxxxxx';
$errmsg .= '1';
break;
case 2:
$mailto = 'webmaster@xxxxxxxxxx';
$errmsg .= '2';
break;
case 3:
$mailto = 'myacct@xxxxxxxxxx';
$errmsg .= '3';
break;
default:
$mailto = 'me@xxxxxxxxxx';
$errmsg .= 'default';
}
.
.
builds an email and sends it to myself.
?>
The email shows up at the "me" address instead of the "myacct" address. The problem is the email shows "etype-: 3 | Case value-: ". This indicates that the switch didn't work at all. Can anyone tell me why?
$aMailTo = array('sales@xxxxxxxxxx', 'support@xxxxxxxxxx',
'webmaster@xxxxxxxxxx', 'myacct@xxxxxxxxxx');
$mailTo = 'me@xxxxxxxxxx'; // default
if (array_key_exists($etype, $aMailTo))
$mailTo = $aMailTo[$etype];
$errmsg .= "$etype";
By the way, in your code above, you haven't closed off
the comment that starts on the Define the mailto address line.
Also, though it shouldn't make a difference in the switch
statement, the type of $etype is string.
Csaba Gabor from Vienna
.
- Follow-Ups:
- Re: Switch
- From: Bill H
- Re: Switch
- References:
- Switch
- From: Bill H
- Switch
- Prev by Date: Switch
- Next by Date: resizing an image with the gd library
- Previous by thread: Switch
- Next by thread: Re: Switch
- Index(es):
Relevant Pages
|