标题不会重定向我,无法弄清楚原因

时间:2017-04-01 11:59:48

标签: php mysql

我无法弄清楚为什么这不会重定向我或告诉我任何错误,它会添加到数据库但它不会重定向

<?php
    ob_start();

        $db = mysqli_connect("localhost", "root", "", "autentificare");

        if (isset($_POST['register_btn'])){
            session_start();
            $username = mysql_real_escape_string($_POST['username']);
            $email = mysql_real_escape_string($_POST['email']);
            $password = mysql_real_escape_string($_POST['password']);
            $passwordc = mysql_real_escape_string($_POST['passwordc']);

            if ($password == $passwordc){
                    $password = md5($password);
                    $sql = "INSERT INTO users(username, email, password) VALUES('$username', '$email', '$password')" ;
                    mysqli_query($db, $sql);
                    $_SESSION['message'] = "Succesfully logged in";
                    $_SESSION['username'] = $username;
                    header( "location : home.php");
            }else{
                    $_SESSION['message'] = "Passwords do not match";

            }
        }
    ob_end_flush();
    ?>  

1 个答案:

答案 0 :(得分:2)

您正在发送标题,但随后让脚本继续处理。使用此:

header( "location : home.php");
exit();