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********@myco rp.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.n et';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp .net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@myco rp.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 5 1262
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.n et';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp .net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@myco rp.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****@my corp.net', 's******@mycorp .net',
'w********@myco rp.net', 'm*****@mycorp. net');
$mailTo = 'm*@mycorp.net' ; // default
if (array_key_exis ts($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
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********@myco rp.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.n et';
$errmsg .= '0';
break;
case 1:
$mailto = 's******@mycorp .net';
$errmsg .= '1';
break;
case 2:
$mailto = 'w********@myco rp.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*******@attgl obal.net
=============== ===
Csaba:
How stupid could I get. The missing "close comment" was the problem.
I tried the array but it seems the:
if (array_key_exis ts($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.comwr ote 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.n et'; $errmsg .= '0'; break; case 1: $mailto = 's******@mycorp .net'; $errmsg .= '1'; break; case 2: $mailto = 'w********@myco rp.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****@my corp.net', 's******@mycorp .net',
'w********@myco rp.net', 'm*****@mycorp. net');
$mailTo = 'm*@mycorp.net' ; // default
if (array_key_exis ts($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
Bill H wrote:
$mailto = 'm*@mycorp.net' ;
For future reference, when using an example domain name, please use
example.(com|ne t|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/
Thanks Toby.
It neverceases to amaze the breadth of information all of us are unaware of.
:-)
Bill
"Toby A Inkster" <us**********@t obyinkster.co.u kwrote in message
news:3c******** ****@ophelia.g5 n.co.uk...
Bill H wrote:
> $mailto = 'm*@mycorp.net' ;
For future reference, when using an example domain name, please use
example.(com|ne t|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/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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"
|
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 switch-case has a variable (most probably an enumeration) &
associated symbols or integral value. Selection is made, base on what
symbol/value the variable holds. So
|
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 65536
switch cases. The program would crash when it attempts to run.
C++ Compiler does not support above 64K switch cases. I tried to
set a limit to 2048 switch cases and 4096 switch cases, but the
problem exists when program crashed again.
Do...
|
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 'case' code snippet
does not. (the code's function is illustrative.)
//////////////////////////////////////////
//////// working 'if/else' switch ////////
//////////////////////////////////////////
|
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?
In terms of generated machine code, how does hundreds of cases in a switch
differ from hundreds of if-elses? Do compilers or processors do any
optimization on such structured code? Do I need to worry about the
performance, usually?
| |
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. Now I find myself wanting to use "Select Case" i.e., "switch" in C# regularly, but I always have to find another way b/c C#'s switch statement only allows static or integral variables. For example, I often want to use a switch statement based on the...
|
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 1");
break;
|
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;
|
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 parameters value
and signal ID. Signal Id is used to get a user configurable parameter
inside a configuration file, which depends on the type of switch.
I have implemented it as under. Please ignore those magic numbers as I
have mimized logic to...
|
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 statements in switch #2 enter a 3rd switch.
I don't receive any compile errors except whenever I attempt to add default
switches to switches 2 or 3.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |