Re: Switch Statement

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.


On 10/19/2013 09:10 PM, German Geek wrote:
         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


On 30 September 2013 06:28, mrfroasty <mrfroasty@xxxxxxxxx> wrote:

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

On 09/29/2013 04:33 AM, Ethan Rosenberg wrote:
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


--
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





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux