473,385 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Switch

I wrote a PHP script that the user decides who they want to send the email
to based on the selection from a "dropdown" box. The essential part of the
script that I'm having problems with is:

<?php

/* Pre-defined script variables. */
$eol = "\n";
$mailto = 'm*@mycorp.net';
$mailfrom = 'w********@mycorp.net';
$subject = 'Contact Us Request';

/* 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 = 's****@mycorp.net';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp.net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@mycorp.net';
$errmsg .= '2';
break;
case 3:
$mailto = 'm*****@mycorp.net';
$errmsg .= '3';
break;
default:
$mailto = 'm*@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?

Thanks,

Bill
Nov 20 '07 #1
5 1248
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 = 's****@mycorp.net';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp.net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@mycorp.net';
$errmsg .= '2';
break;
case 3:
$mailto = 'm*****@mycorp.net';
$errmsg .= '3';
break;
default:
$mailto = 'm*@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('s****@mycorp.net', 's******@mycorp.net',
'w********@mycorp.net', 'm*****@mycorp.net');
$mailTo = 'm*@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
Nov 20 '07 #2
Bill H wrote:
I wrote a PHP script that the user decides who they want to send the email
to based on the selection from a "dropdown" box. The essential part of the
script that I'm having problems with is:

<?php

/* Pre-defined script variables. */
$eol = "\n";
$mailto = 'm*@mycorp.net';
$mailfrom = 'w********@mycorp.net';
$subject = 'Contact Us Request';

/* 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 = 's****@mycorp.net';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp.net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@mycorp.net';
$errmsg .= '2';
break;
case 3:
$mailto = 'm*****@mycorp.net';
$errmsg .= '3';
break;
default:
$mailto = 'm*@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?

Thanks,

Bill
Bill,

Try

case '0':
case '1':
etc

Or, when I know it's a numeric value, I use:

$etype= isset($_POST['etype']) ? intval($_POST['etype']) ? 0;

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Nov 20 '07 #3
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" <cs***@z6.comwrote in message
news:c2**************************@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 = 's****@mycorp.net';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp.net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@mycorp.net';
$errmsg .= '2';
break;
case 3:
$mailto = 'm*****@mycorp.net';
$errmsg .= '3';
break;
default:
$mailto = 'm*@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('s****@mycorp.net', 's******@mycorp.net',
'w********@mycorp.net', 'm*****@mycorp.net');
$mailTo = 'm*@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

Nov 20 '07 #4
Bill H wrote:
$mailto = 'm*@mycorp.net';
For future reference, when using an example domain name, please use
example.(com|net|org). Mark Segal, who owns mycorp.net might not be
happy with you posting valid e-mail addresses at his domain to Usenet,
and potentially attracting spammers to it.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 13 days, 16:31.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/
Nov 20 '07 #5
Thanks Toby.

It neverceases to amaze the breadth of information all of us are unaware of.
:-)

Bill

"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:3c************@ophelia.g5n.co.uk...
Bill H wrote:
> $mailto = 'm*@mycorp.net';

For future reference, when using an example domain name, please use
example.(com|net|org). Mark Segal, who owns mycorp.net might not be
happy with you posting valid e-mail addresses at his domain to Usenet,
and potentially attracting spammers to it.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 13 days, 16:31.]

USD/EUR Exchange Rate Graph
http://tobyinkster.co.uk/blog/2007/11/18/usd-eur/

Nov 20 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Rudi Hansen | last post by:
I dont seem to be able to find the switch statement in Python. I would like to be able to do switch(var) case 1 : print "var = 1" case 2: print "var = 2"
10
by: Myster Ious | last post by:
Polymorphism replaces switch statements, making the code more compact/readable/maintainable/OO whatever, fine! What I understand, that needs to be done at the programming level, is this: a...
5
by: Bryan Parkoff | last post by:
C++ programmers and I tried to experience by writing 65536 switch cases. It is too large for Windows XP and other operating system to handle. It looks like that JMP Table obtains 256K bytes for...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
65
by: He Shiming | last post by:
Hi, I just wrote a function that has over 200 "cases" wrapped in a "switch" statement. I'm wondering if there are performance issues in such implementation. Do I need to optimize it some way? ...
3
by: pgraeve | last post by:
I am a convert from VB to C# so bear with me on this "conversion" question C# switch statement seems to be the closest relative to VB's Select Case. I used VB's Select Case statement liberally. ...
11
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
12
by: | last post by:
Is it fine to call another method from Switch? Eg. Switch (stringVar) { case ("a"): somVar = "whatever"; Another_Method(); //call another method return;
7
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
11
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Can switch statements be nested? I've got a large routine that runs off of a switch statement. If one of the switches in switch #1 is true, that enters switch statement #2. Some of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.