Re: Switch



Bill H wrote:
/* Initialize a clean array to replace $_POST with clean data */
$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?

Isn't it simpler to do:
$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
.



Relevant Pages

  • Re: Switch
    ... if (array_key_exists($etype, $aMailTo)) { ... indicates that the switch didn't work at all. ... the comment that starts on the Define the mailto address line. ... the type of $etype is string. ...
    (comp.lang.php)
  • Re: What is Intelligent Design?
    ... and switch" to the point that they don't have the emotive effect you ... in the sense that Bill was trying to use it. ... intelligent design and teach the controversy is the issue. ...    and specific changes that they would recommend making? ...
    (talk.origins)
  • Re: Dark Week Time Wasting Thread: Inauguration Edition
    ... Key senators have reached a compromise on a bill that would delay the nation's switch to all-digital television from next month until June 12. ... The National Telecommunications and Information Administration, which is running the coupon program, has hit its $1.34 billion funding limit and is now sending out new coupons only as unredeemed vouchers reach a 90-day expiration date. ...
    (alt.fan.letterman)
  • Re: Multi user CP/M
    ... Bill H wrote: ... Was it a task switch / time slice where the same CPU switched between ... multiple users, or were multiple CPU's used and the hardware shared? ... Most interprocessor comms was done with semaphores and simple FIFO utilities - declare a global FIFO pool, assign per-user access rights, and each user can send and receive from their FIFO. ...
    (comp.os.cpm)
  • Re: Does it even exist? I want one!
    ... So if you tapped a pushbutton into where ine bill validator ... usually inputs its pulses you could just click off credits or large ... switch on a game as others have suggested and you may be in business. ...
    (rec.games.pinball)