-1

I have a php page that accepts and processes a form submission, the page displays normally when it is requested, however if the page is submitted and its form validation fails, the page suppose to be re-displayed with the form errors, but on page re-display, php displays a blank page when it reaches the error processing block. Here is the code that processes the validation errors:

 <?php  if(isset($errorLog) and is_array($errorLog)): ?>
                <div class="alert alert-danger">
                    <?php $output = '';
                     if($errorLog['message'] == '') {
                        $output = "<ul class='error-list'>";

                        foreach($errorLog as $key => $value) {
                            if ($key != 'has_error_occured') {

                                $output .= "<li><strong>{html($key)}</strong>
                                            <span>{html($value)} </span></li>";
                            }
                        }
                        $output .= "</ul>";
                     } else {
                         $msg = $errorLog['message'];
                       $output .= "<p>{html($msg)}</p>";

                     }
                     echo $output;
                    ?>
                </div>
            <?php endif; ?>

and here is the code that processes the form submission

if(isset($_GET['transfer']) or
        (isset($_POST['action']) and $_POST['action'] == TRANSFER)){

        $transfer_type = $_GET['ttype'];

        if(isset($_POST['action']) and

            $_POST['action'] == TRANSFER){

            //process money transfer.
            $log = process_transfer();
            if(isset($log) and is_array($log)){

                if($log['has_error_occured']){
                    $_SESSION['error_log'] = $log;

                    //unset log
                    unset($log);

                    include_once $docRoot . '/users/temp/tranfer.html.php';
                    exit();
                }else{
                    $_SESSION['transfer_msg'] = "Your international
                    transfer was processed successfully";

                    header('Location: ?summary');
                }
            }
            //reload primary page.
            header('Location: .');


        }else{

            include_once $docRoot . '/users/temp/tranfer.html.php';
            exit();
        }
    }

Note:

  1. I have tried passing the error array as a global variable as you can see in the code snippet above.

  2. I have also tried passing it in a session.

  3. I also have tried using output buffering by appending the ob_start() at the beginning and ob_end_flush() at the end the form script.

  4. I have also added error_reporting(-1); ini_set('display_errors', true); at the start of the form script so as to know if the page encounters any error during processing, all to no avail.

  5. I am using PhpStorm with XAMPP v3.2.1 for development on windows 7.

Please, any help as to the cause of this nightmare will be appreciated. Thanks.

Janyk
  • 571
  • 3
  • 18
Cizaphil
  • 490
  • 1
  • 6
  • 23
  • 4
    Anything in the error log? – Ed Heal Feb 06 '16 at 05:40
  • 1
    `$_GET['transfer']` and `$_POST['action'] == TRANSFER` isn't it bad. mixing get and post – Alive to die - Anant Feb 06 '16 at 05:42
  • 1
    Possible duplicate of [Reference - What does this error mean in PHP?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – CBroe Feb 06 '16 at 05:54
  • nothing just blank file after the occurrence of the error output code block above – Cizaphil Feb 06 '16 at 06:01
  • 1
    Have you tried replacing your `and` keywords with `&&`? That can sometimes make a difference: http://stackoverflow.com/questions/2803321/and-vs-as-operator – Toastrackenigma Feb 06 '16 at 06:04
  • @Toastrackenigma did that now, no difference. Also changed all the $_GET and $_POST still nothing. – Cizaphil Feb 06 '16 at 06:11
  • 1
    The first place you should always look when you encounter an issue like this is in your PHP error logs. – kojow7 Feb 06 '16 at 06:11
  • 1
    Do you have an error_log location specified in your php.ini file? If you put random echo statements in your script do any of them show up? Specifically try placing an echo on the first line after your opening – kojow7 Feb 06 '16 at 06:17
  • You can also try adding an `exit` statement after your echo to stop the script before any error is encountered. – kojow7 Feb 06 '16 at 06:25

2 Answers2

1
  1. If you wanna use $_GET and $_POST then better use $_REQUEST, it allows to access both $_GET and $_POST

  2. not TRANSFER but it should be "TRANSFER"

  3. if errorlog is session data then it should be

    if(isset($_SESSION['errorLog']) and is_array($_SESSION['errorLog'])):

  4. i didn't find any thing created by name message

    if($errorLog['message'] == '')

    why u used it, i think it must be 'has_error_occured'

0

I discovered the problem through the output of php_error_log and through the various suggestions in the comments above, the problem problem was that I didn't check if the $erroLog['message'] was set before accessing it. But shouldn't php have outputted a warning instead of resorting to such indeterminate option of not fully executing the rest of the document?

Cizaphil
  • 490
  • 1
  • 6
  • 23