Re: Re: error checking a null array

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

 



Jack Jackson wrote:
AAarg.


Okay, thanks to all of you I've decided that any field name I need to see will be sent to $_SESSION['required_fields'] and basta.

Then after the submit button is pressed, I am doing this:



reset($_SESSION['required_fields']);

reset is not required when using foreach. and given that you have probably
not looped that item

  foreach ($_SESSION['required_fields'] as $fieldname)
    {
       if (!isset($_POST[$fieldname]) || empty($_POST[$fieldname]))
        {
        $message[$fieldname]=1;
        include_once(QUESTIONS . 'q.inc');
        }
    }//error check



you may be getting into trouble because of php's typecasting - try using
fielnames that are strings that do not auto cast to integers (which can be
used as array keys for indexed arrays) e.g. "cb1" instead of "1"


And this is *almost* working: it seems to crap out after the first loop through the $_SESSION['required_field'] array.

The array says:

Array ( [required_fields] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 1 [5] => 2 [6] => 3 [7] => 4 [8] => 1 [9] => 2 [10] => 3 [11] => 4 ) )

$_POST says:

Array ( [action] => [process]process [1] => [2] => 68 [3] => [4] => )

that does not look like valid output from var_dump() neither does the output you
show for $_SESSION['required_field'].


So you see, there's an answer specified for the value of question [2].

But $messages says only:

$message: array(1) { [1]=>  int(1) }


Why is it dying after the first loop through?

is it? (use print_r() or var_dump() inside the loop to see what is happening)

NOT SO SUBTLE HINT: USE echo, print_r() and var_dump() until either you fingers or
your eyes start to bleed ;-) if you still haven't figured it out by then it's
time to see a doctor -


Thanks in advance


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