mpdc
mpdc

Reputation: 3560

PHP function getting confused with a second parameter/argument

At the end of all of my scripts, I run a function closeConnection, i.e.:

closeConnection("success");

function closeConnection($note) {
    if ($note === "success") { $append = "?success"; }
    if ($note === "blank") { $append = "?blank"; }
    mysql_close();
    header("Location: index.php" . $append . "");
    exit();
}

This runs smoothly.

However, I now want my closeConnection() function to take two arguments, so that I can choose a different page to redirect to. This is how it looks the second time around:

closeConnection("updated", "view");

function closeConnection($note, $header) {
    $header = $header; // Not sure if needed, doesn't work with or without.
    if ($note === "updated") { $append = "?updated"; }
    if ($note === "blank") { $append = "?blank"; }
    mysql_close();
    header("Location: " . $header . ".php" . $append . "");
    exit();
}

Desired result: Redirect to view.php?updated

Actual result: Redirect to .php?blank

Upvotes: 0

Views: 82

Answers (1)

Jacob Cohen
Jacob Cohen

Reputation: 1272

In my experience, you are calling closeConnection("updated"); somewhere before the closeConnection("updated", "view"); and you forgot to remove it or something.

Make sure you didn't forget previous commands, and that you are in fact saving the right file.

Upvotes: 1

Related Questions