Q:

PHP Redirect with data session destroys

I'm trying to have a formular with header("location"). 
And it workes just fine except one thing. When im trying to set the session that is holding the message it sets the session but when im trying to write it out, the problems starting.. 
Its like he go inside the if then delete the cookie, jumps out of the if and trys to get there again..
Here is my code:
if (isset($_SESSION['sess_error'])) { 
    echo '<div class="alert alert-danger">';
    foreach ($_SESSION['sess_error'] as $val) { 
        echo $val.'<br>'; 
    }
    unset($_SESSION['sess_error']);
}

if (empty($_POST['username'])) { $error[] = 'Du måste fylla i ett användarnamn...'; }    
if (empty($_POST['password'])) { $error[] = 'Du måste fylla i ett lösenord...'; }
elseif ($sql->num_rows == 0) { $error[] = 'Något fel uppstog, du kunde inte bli inloggad...'; }
if (count($error) > 0) { 
    $_SESSION['sess_error'] = $error;
}

Anyone got any idea why this is happening and what can I do to prevent it? 
The whole script: 
<?php
SESSION_START();
    if (isset($_POST['login'])) { 
            $error = null;
            $username = $_POST['username'];
            $password = $_POST['password'];
            $sql = $mysqli->query("SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1");
            if (empty($_POST['username'])) { $error[] = 'Du måste fylla i ett användarnamn...'; }
            if (empty($_POST['password'])) { $error[] = 'Du måste fylla i ett lösenord...'; }
            elseif ($sql->num_rows == 0) { $error[] = 'Något fel uppstog, du kunde inte bli inloggad...'; }
                if (count($error) > 0) { 
                    $_SESSION['sess_error'] = $error;
                }
                else { 
                    while ($r = $sql->fetch_array()) { 
                        $_SESSION['sess_username'] = $r['username']; 
                        $_SESSION['sess_userID'] = $r['userID'];
                        $_SESSION['sess_admin'] = $r['admin']; 
                        $_SESSION['sess_logg'] = 1;
                    }
                }
                header("Location: ./");
            }
?>

A:

I solved the whole problem, i just had to add an exit; after the header(""); and it worked just fine!

