after redirecting to index.php sign-up form closed

When I clicked on register button leaving an empty field then it should be displaying an error message that username or email is required. Actually when I click on register then page redirects to index.php and I have to click to button to see a form and after that I can see the error on that form. I dont want this. I want to stay on register page if user click on register upon leaving any empty field and also display the error mesaage.

This is html code

<form action="<?= ROOT_URL ?>signup-logic.php" method="POST">
                <div class="popup-form" id="my-form">
                    <div class="form-box">
                        <i id="my-close-btn" class="uil uil-multiply"></i>
                        <div class="button-box">
                            <div id="btn"></div>
                            <button id="log-btn" class="toggle-btn" type="button">Log In</button>
                            <button id="reg-btn" class="toggle-btn" type="button">Register</button>


                        </div>
                        <div class="social-icons">
                            <a href="#"><i class="fa-brands fa-twitter"></i></a>
                            <a href="#"><i class="fa-brands fa-facebook"></i></a>
                            <a href="#"><i class="fa-brands fa-google"></i></a>
                        </div>
                        <div id="login" class="form-group">
                            <input type="text" class="input-field" placeholder="Username">
                            <input type="text" class="input-field" placeholder="Password">
                            <input type="checkbox" id="rem-chk" class="check-box"><span class="rem">Remember Me</span>
                            <button type="submit" class="submit-btn">Log In</button>
                            <p id="r_msg">Registration Successful. Please log In</p>
                        </div>
                        <div id="register" class="form-group">
                            <?php if (isset($_SESSION['signup'])) : ?>
                                <div class="err_msg">
                                    <p id="g_msg">
                                        <?=
                                        $_SESSION['signup'];
                                        unset($_SESSION['signup']);
                                        ?>
                                    </p>
                                </div>
                            <?php endif ?>
                            <input type="text" name="email" value="<?= $email ?>" class="input-field" placeholder="Email">
                            <input type="text" name="username" value="<?= $username ?>" class="input-field" placeholder="Username">
                            <input type="text" name="createpassword" value="<?= $createpassword ?>" class="input-field" placeholder="Password">
                            <input type="text" name="confirmpassword" value="<?= $confirmpassword ?>" class="input-field" placeholder="Confirm Password">
                            <div class="type-chk">
                                <input type="checkbox" class="check-box">
                                <span class="i-agree">I agree to terms & conditions</span>
                            </div>
                            <button type="submit" name="submit" class="submit-btn">Register</button>
                        </div>
                    </div>
                </div>

                <!-- <a href="" class="pro-btn" id="my-form-btn">Visit Us To Promote Your Website</a> -->
                <button class="pro-btn" type="button" id="my-form-btn">Click To Promote Your Website</button>
            </form>

This is php script file

require 'config/database.php';

if(isset($_POST['submit'])) {
    $email = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL);
    $username = filter_var($_POST['username'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $createpassword = filter_var($_POST['createpassword'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $confirmpassword = filter_var($_POST['confirmpassword'], FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    // echo $email;
    
    if(!$email) {
        $_SESSION['signup'] = 'Please enter a valid email';
    } else if (!$username) {
        $_SESSION['signup'] = 'Please enter a username';
    } else if (strlen($createpassword) < 8 || strlen($confirmpassword) < 8) {
        $_SESSION['signup'] = 'Password should be 8+ character';
    } else {

        if($createpassword !== $confirmpassword) {
            $_SESSION['signup'] = 'Password do not match';
        } else {
            $hashed = password_hash($createpassword, PASSWORD_DEFAULT);

            $user_chk_query = "SELECT * FROM users WHERE username = '$username' OR email = '$email'";
            $user_chk_result = mysqli_query($conn, $user_chk_query);
            if(mysqli_num_rows($user_chk_result) > 0) {
                $_SESSION['signup'] = "username or email already exists";
                echo "username or email already exists";
            }
        }
    }

    if(isset($_SESSION['signup'])) {
        //pass form data back to page
        $_SESSION['signup-data'] = $_POST;
        header('location: '. ROOT_URL . 'index.php');
        die();
    } else {
        //otherwise insert user into database
        $insert_query = "INSERT INTO users SET email = '$email', username = '$username', password = '$hashed'";
        $insert_user = mysqli_query($conn,$insert_query);

        if(!mysqli_error($conn)) {
            //redirect to login page
            $_SESSION['signup-success'] = 'Registration successful. Please log in';
            header('location: '. ROOT_URL . 'index.php');
           die();
        }
    }
} else {
    header('location: '. ROOT_URL . 'index.php');
    die();
}```

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật