Discussion:
Switch Statement
Ethan Rosenberg
2013-09-29 02:33:12 UTC
Permalink
Dear List -

I have a working program. I made one change in a switch statement, and
it does not work. I'm probably missing something fundamental.

Here are some code SNIPPETS... [please note that all my debug
statements are at the left margin]

Setup...

<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);

ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= "already_seen")
show_welcome();

//end setup
function show_welcome() //this is the input screen
{
<snip>

echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";

<snip>
}


//end input screen

//Switch statement

echo 'before';
print_r($_POST); //post#1

switch ( $_POST['next_step'] )
{

case 'step20':
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20

<snip>
} //end switch



post#1

beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20

)

Cust_Num state and Zip are as entered.

The switch statement is never entered, since post#2 is never displayed,
and neither good() or bad() functions are entered.


TIA

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2013-09-29 02:53:15 UTC
Permalink
Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.

Aziz


On Sat, Sep 28, 2013 at 10:33 PM, Ethan Rosenberg <
Post by Ethan Rosenberg
Dear List -
I have a working program. I made one change in a switch statement, and it
does not work. I'm probably missing something fundamental.
Here are some code SNIPPETS... [please note that all my debug statements
are at the left margin]
Setup...
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_**errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$**password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_**seen']!= "already_seen")
show_welcome();
//end setup
function show_welcome() //this is the input screen
{
<snip>
echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";
<snip>
}
//end input screen
//Switch statement
echo 'before';
print_r($_POST); //post#1
switch ( $_POST['next_step'] )
{
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
<snip>
} //end switch
post#1
beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20
)
Cust_Num state and Zip are as entered.
The switch statement is never entered, since post#2 is never displayed,
and neither good() or bad() functions are entered.
TIA
Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ethan Rosenberg
2013-09-29 05:34:02 UTC
Permalink
Post by Aziz Saleh
Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.
Aziz
<snip>

Aziz -

Used var_dump no further information

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Aziz Saleh
2013-09-29 14:04:23 UTC
Permalink
What is the output?


On Sun, Sep 29, 2013 at 1:34 AM, Ethan Rosenberg <
Post by Ethan Rosenberg
Post by Aziz Saleh
Ethan, can you do a var_dump instead of print_r. It might be that next_step
has spaces in it causing the switch to not match.
Aziz
<snip>
Aziz -
Used var_dump no further information
Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-09-29 03:33:23 UTC
Permalink
Post by Ethan Rosenberg
Dear List -
I have a working program. I made one change in a switch statement, and
it does not work. I'm probably missing something fundamental.
Here are some code SNIPPETS... [please note that all my debug
statements are at the left margin]
Setup...
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= "already_seen")
show_welcome();
//end setup
function show_welcome() //this is the input screen
{
<snip>
echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";
<snip>
}
//end input screen
//Switch statement
echo 'before';
print_r($_POST); //post#1
switch ( $_POST['next_step'] )
{
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
<snip>
} //end switch
post#1
beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20
)
Cust_Num state and Zip are as entered.
The switch statement is never entered, since post#2 is never displayed,
and neither good() or bad() functions are entered.
TIA
Ethan
Once again you are posting code that has no chance of running. And
since you are DISABLING error reporting with that "-2" value you won't
even know you have bad code.

Try again. Post#2 will never display since you aren't printing it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-09-29 03:59:29 UTC
Permalink
Post by Ethan Rosenberg
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
Ethan,Ethan,Ethan - what is all this "stuff" you have at the top??? Do
you know how any of this is supposed to be written? You can not put
Constants in quotes - they become just plain strings then, not Constants
with the predefined values you (and the functions) are expecting. For
example, 'on' is NOT the same as the use of the word : on. And your
error_reporting setting (which you are attempting to do TWICE) is
actually causing your script to NOT show any errors, which is preventing
you from seeing that your script dies at the misspelled print statement
and never gets to the pair of if statements that should call your good
and bad functions.

Hate to do this to you, but you've been attempting to pick up PHP for
two years now almost and from this latest post you appear to not have
learned anything.

And WHY would you EVER want to have a time limit of 2400 seconds???????

And stop burying functions in the middle of your straight line code.
It's ridiculous and makes reading your scripts a royal PIA.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ethan Rosenberg
2013-09-29 05:29:57 UTC
Permalink
Post by Jim Giner
Post by Ethan Rosenberg
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
Ethan,Ethan,Ethan - what is all this "stuff" you have at the top??? Do
you know how any of this is supposed to be written? You can not put
Constants in quotes - they become just plain strings then, not Constants
with the predefined values you (and the functions) are expecting. For
example, 'on' is NOT the same as the use of the word : on. And your
error_reporting setting (which you are attempting to do TWICE) is
actually causing your script to NOT show any errors, which is preventing
you from seeing that your script dies at the misspelled print statement
and never gets to the pair of if statements that should call your good
and bad functions.
Hate to do this to you, but you've been attempting to pick up PHP for
two years now almost and from this latest post you appear to not have
learned anything.
And WHY would you EVER want to have a time limit of 2400 seconds???????
And stop burying functions in the middle of your straight line code.
It's ridiculous and makes reading your scripts a royal PIA.
Jim -

Thanks.

Changed error_reporting to -1. No error messages. No change in output.

Ethan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-09-29 05:38:34 UTC
Permalink
Post by Ethan Rosenberg
Post by Jim Giner
Post by Ethan Rosenberg
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
Ethan,Ethan,Ethan - what is all this "stuff" you have at the top??? Do
you know how any of this is supposed to be written? You can not put
Constants in quotes - they become just plain strings then, not Constants
with the predefined values you (and the functions) are expecting. For
example, 'on' is NOT the same as the use of the word : on. And your
error_reporting setting (which you are attempting to do TWICE) is
actually causing your script to NOT show any errors, which is preventing
you from seeing that your script dies at the misspelled print statement
and never gets to the pair of if statements that should call your good
and bad functions.
Hate to do this to you, but you've been attempting to pick up PHP for
two years now almost and from this latest post you appear to not have
learned anything.
And WHY would you EVER want to have a time limit of 2400 seconds???????
And stop burying functions in the middle of your straight line code.
It's ridiculous and makes reading your scripts a royal PIA.
Jim -
Thanks.
Changed error_reporting to -1. No error messages. No change in output.
Ethan
CORRECT ALL THE WRONG SHIT AND YOU"LL GET ERROR MESSAGES!!!
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Giner
2013-09-29 05:43:39 UTC
Permalink
Post by Ethan Rosenberg
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
This is what you should have in place of all of the above:

session_start();
error_reporting(E_ALL | E_STRICT | E_NOTICE); ini_set('display_errors',
'1');
set_time_limit(2);// if you use more than 2 secs you have a problem
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
mrfroasty
2013-09-29 17:28:07 UTC
Permalink
Hello,

I suggest you put default in that switch statement and var_dump the
$_POST.That should be enough for a programmer to pin point what goes wrong.

P:S
**You might want to consider versioning your codes to go back into its
history to see what has changed.

Muhsin
Post by Ethan Rosenberg
Dear List -
I have a working program. I made one change in a switch statement,
and it does not work. I'm probably missing something fundamental.
Here are some code SNIPPETS... [please note that all my debug
statements are at the left margin]
Setup...
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= "already_seen")
show_welcome();
//end setup
function show_welcome() //this is the input screen
{
<snip>
echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";
<snip>
}
//end input screen
//Switch statement
echo 'before';
print_r($_POST); //post#1
switch ( $_POST['next_step'] )
{
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
<snip>
} //end switch
post#1
beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20
)
Cust_Num state and Zip are as entered.
The switch statement is never entered, since post#2 is never
displayed, and neither good() or bad() functions are entered.
TIA
Ethan
--
Extra details:
OSS:Gentoo Linux
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,PHP
Typo:40WPM
url:http://www.mzalendo.net
url:http://www.zanbytes.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
German Geek
2013-10-20 04:10:21 UTC
Permalink
<?php
<form method="POST" action="">
<input name="next_step" type="text" value="step20" />
<input type="submit" value="press" />
</form>
<pre>
<?php
function good() {
echo "we're GOOD";
}
function bad() {
echo "BAD";
}
//Switch statement

echo "\nbefore\n";
var_dump($_POST); //post#1

print_r($_POST); //post#2
switch ( $_POST['next_step'] )
{

case 'step20':
{
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20

} //end switch
?>

works fine when you hit submit. Try to isolate the error by running a
simplified script like this one next time before posting.
Also, you had "pint_r" instead of "print_r" somewhere.

I would also set these in php.ini:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
; OR even
error_reporting = E_ALL & E_DEPRECATED & E_STRICT
; AND
display_errors = On

and correct all errors and warnings if you have time, but even if not...

Question to all: Does this formatting work for you or is it too much,
annoying or anything else bad?

Tim-Hinnerk Heuer

Twitter: @geekdenz
Blog: http://www.thheuer.com
Post by mrfroasty
Hello,
I suggest you put default in that switch statement and var_dump the
$_POST.That should be enough for a programmer to pin point what goes wrong.
P:S
**You might want to consider versioning your codes to go back into its
history to see what has changed.
Muhsin
Post by Ethan Rosenberg
Dear List -
I have a working program. I made one change in a switch statement,
and it does not work. I'm probably missing something fundamental.
Here are some code SNIPPETS... [please note that all my debug
statements are at the left margin]
Setup...
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= "already_seen")
show_welcome();
//end setup
function show_welcome() //this is the input screen
{
<snip>
echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";
<snip>
}
//end input screen
//Switch statement
echo 'before';
print_r($_POST); //post#1
switch ( $_POST['next_step'] )
{
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
<snip>
} //end switch
post#1
beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20
)
Cust_Num state and Zip are as entered.
The switch statement is never entered, since post#2 is never
displayed, and neither good() or bad() functions are entered.
TIA
Ethan
--
OSS:Gentoo Linux
profile:x86
Hardware:msi geforce 8600GT asus p5k-se
location:/home/muhsin
language(s):C/C++,PHP
Typo:40WPM
url:http://www.mzalendo.net
url:http://www.zanbytes.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Lucas
2013-10-21 23:18:00 UTC
Permalink
Try this

<?php

if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {

// Post#1
var_dump($_POST);

// Check conditions...
if ( isset($_POST['next_step']) ) {
switch ( $_POST['next_step'] ) {
case 'step20':
echo "\n\nCustomer Number: (#{$_POST['Cust_Num']})\n\n";
break;
}
}
}

?>
<form method="POST" action="">
<input name="next_step" type="text" value="step20" />
<input type="submit" value="press" />
</form>

#####################

Obviously, you never want to output raw input in this manor, but for a quick
test, you should be fine.
Post by Ethan Rosenberg
switch ( $_POST['next_step'] )
{
{
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
} //end switch
?>
works fine when you hit submit. Try to isolate the error by running a
simplified script like this one next time before posting.
Also, you had "pint_r" instead of "print_r" somewhere.
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
; OR even
error_reporting = E_ALL & E_DEPRECATED & E_STRICT
; AND
display_errors = On
and correct all errors and warnings if you have time, but even if not...
Question to all: Does this formatting work for you or is it too much,
annoying or anything else bad?
Tim-Hinnerk Heuer
Blog: http://www.thheuer.com
Post by mrfroasty
Hello,
I suggest you put default in that switch statement and var_dump the
$_POST.That should be enough for a programmer to pin point what goes wrong.
P:S
**You might want to consider versioning your codes to go back into its
history to see what has changed.
Muhsin
Post by Ethan Rosenberg
Dear List -
I have a working program. I made one change in a switch statement,
and it does not work. I'm probably missing something fundamental.
Here are some code SNIPPETS... [please note that all my debug
statements are at the left margin]
Setup...
<?php
session_start();
session_name("STORE");
set_time_limit(2400);
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(-2);
ini_set('error_reporting', 'E_ALL | E_STRICT');
ini_set('html_errors', 'On');
ini_set('log_errors', 'On');
require '/home/ethan/P/wk.inc'; //password file
$db = "Store";
$cxn =mysqli_connect($host,$user,$password,$db);
if (!$cxn)
{
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}// no error
if($_REQUEST['welcome_already_seen']!= "already_seen")
show_welcome();
//end setup
function show_welcome() //this is the input screen
{
<snip>
echo " <input type='hidden' name='welcome_already_seen'
value='already_seen'>";
echo " <input type='hidden' name='next_step' value='step20' />";
<snip>
}
//end input screen
//Switch statement
echo 'before';
print_r($_POST); //post#1
switch ( $_POST['next_step'] )
{
{
pint_r($_POST); //post#2
echo 'step20';
if(!empty($_POST['Cust_Num']))
good();
if(empty($_POST['Cust_Num']))
bad();
break;
} //end step20
<snip>
} //end switch
post#1
beforeArray
(
[Cust_Num] => 123
[Fname] =>
[Lname] =>
[Street] =>
[City] =>
[state] => NY
[Zip] => 10952
[PH1] =>
[PH2] =>
[PH3] =>
[Date] =>
[welcome_already_seen] => already_seen
[next_step] => step20
)
Cust_Num state and Zip are as entered.
The switch statement is never entered, since post#2 is never
displayed, and neither good() or bad() functions are entered.
TIA
Ethan
--
Jim Lucas

http://www.cmsws.com/
http://www.cmsws.com/examples/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...