sineverba
sineverba

Reputation: 5172

PHP: blank page but no error when confronting NULL value in a function

No error in log of Apache... This is my function:

function feedback($type,$message,$link=NULL) {
    if ( (isset($_POST['ajaxFeedback'])) && ($_POST['ajaxFeedback']==true) ) {
        echo '<div class="alert alert-'.$type.'">';
            echo '<p>'.$message.'</p>';
        echo '</div>';
        exit;
    } else {
        $_SESSION['typeMessage']    = $type;
        $_SESSION['message']        = $message;
        if (isset($link)) {
            header('Location: '.LINK_ASSOLUTO.$link);
        }
        exit;
    }
}

if i call it with

feedback('success','All queries OK',$link=NULL);

i obtain stop of execution of page (all rest of page will be blank). Also if I omit $link and if I pass $link without the "=NULL".

If I pass a link, e.g.

feedback('success','All queries OK','/index.php');

all works (i've used this function in several codes).

Help me.. thank you!

Upvotes: 0

Views: 69

Answers (1)

Pitchinnate
Pitchinnate

Reputation: 7556

You can't set a default in the call of a function only the declaration. You should either call:

feedback('success','All queries OK');

or

feedback('success','All queries OK',null);

Also if $link is null and $_POST['ajaxFeedback'] is not set your code just sets session values. However I don't see where you are using session_start()

Upvotes: 3

Related Questions