You are here: Re: Switch « PHP Programming Language « IT news, forums, messages
Re: Switch

Posted by Bill H on 11/20/07 03:01

Csaba:

How stupid could I get. The missing "close comment" was the problem.

I tried the array but it seems the:

if (array_key_exists($etype, $aMailTo)) {
$mailTo = $aMailTo[$etype];
$errmsg .= "$etype"; }

....didn't work but:

$mailTo = $aMailTo[$etype];

....did. Go figure.

Thanks very much.

Bill


"Csaba Gabor" <csaba@z6.com> wrote in message
news:c216a$47423353$506c17c2$5852@news.chello.at...
> 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@mycorp.net';
>> $errmsg .= '0';
>> break;
>> case 1:
>> $mailto = 'support@mycorp.net';
>> $errmsg .= '1';
>> break;
>> case 2:
>> $mailto = 'webmaster@mycorp.net';
>> $errmsg .= '2';
>> break;
>> case 3:
>> $mailto = 'myacct@mycorp.net';
>> $errmsg .= '3';
>> break;
>> default:
>> $mailto = 'me@mycorp.net';
>> $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@mycorp.net', 'support@mycorp.net',
> 'webmaster@mycorp.net', 'myacct@mycorp.net');
> $mailTo = 'me@mycorp.net'; // 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация