使用PHP重新加载提交表单的页面两次

使用PHP重新加载提交表单的页面两次,php,html,twitter-bootstrap,Php,Html,Twitter Bootstrap,最近,我开始用PHP和Bootstrap创建一个简单的网站,其中包含三个PHP页面Header.PHP、Footer.PHP和Home.PHP。在首页我有一个名为注册的接口。点击注册按钮将弹出一个模式(引导模式)在我的home.php页面中,我包含了我的页眉和页脚php文件。我的代码的问题是,当我单击按钮时,模式将被打开,用户将填写表单。提交表单后,用户将被注册,模式将被关闭。但问题是,当我刷新主页时,用户再次注册。因此我需要的是在提交模式表单后重新加载页面,不应再次提交用户。有人能建议我这样做

最近,我开始用PHP和Bootstrap创建一个简单的网站,其中包含三个PHP页面Header.PHP、Footer.PHP和Home.PHP。在首页我有一个名为注册的接口。点击注册按钮将弹出一个模式(引导模式)在我的home.php页面中,我包含了我的页眉和页脚php文件。我的代码的问题是,当我单击按钮时,模式将被打开,用户将填写表单。提交表单后,用户将被注册,模式将被关闭。但问题是,当我刷新主页时,用户再次注册。因此我需要的是在提交模式表单后重新加载页面,不应再次提交用户。有人能建议我这样做吗

这是header.php中的模式

       <div class="modal fade" id="myModalNorm" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <!-- Modal Header -->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span> <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>

            <!-- Modal Body -->
            <div class="modal-body">

                <form class="form" role="form" method="post" action="Home.php">
                    <div class="form-group">
                        <label for="exampleInputEmail1">Email address</label> <input
                            type="email" class="form-control" id="exampleInputEmail1"
                            placeholder="Enter email"  name="userEmail" required=""/>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputUsername1">Username</label> <input
                            type="text" class="form-control" id="exampleInputUsername1"
                            placeholder="Enter username"  name="name" required=""/>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword1">Password</label> <input
                            type="password" class="form-control" id="exampleInputPassword1"
                            placeholder="Password"  name="password" required=""/>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputPassword2">Confirm Password</label> <input
                            type="password" class="form-control" id="exampleInputPassword2"
                            placeholder="Re-enter Password" 
                            name="confirm_password" required=""/>
                    </div>

                    <label class="radio-inline"> <input type="radio" name="gender" value="Male">Male
                    </label> <label class="radio-inline"> <input type="radio"
                        name="gender" value="Female">Female
                    </label> 
                    <div class="checkbox ">
                        <label id="lgcheck"> <input type="checkbox" name= "terms"/> Check me out
                        </label>
                    </div>
                    <button type="submit" class="btn bsubmit btn-primary" name="submit">Submit</button>

                </form>


            </div>

            <!-- Modal Footer -->
            <!-- <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="save"">Save
                    changes</button>
                <button type="button" class="btn btn-default" id="close"
                    data-dismiss="modal">Close</button>
            </div> -->
        </div>
    </div>
</div>

&时代;接近
情态标题
电子邮件地址
用户名
密码
确认密码
男性
女性
看看我
提交
这是我的Home.php文件

     <?php include_once 'Header.php';?>
      <?php include_once 'db/Conection.php';?>
       <div class="container">
<div class="row">
<?php
$register = array ();
/* Form Required Field Validation */
if (isset ( $_POST ['submit'] )) {
    if (isset ( $_POST ['userEmail'] )) {
        $userEmail = $_POST ['userEmail'];
    } 
    if (isset ( $_POST ['name'] )) {
        $name = $_POST ['name'];
    }
    if (isset ( $_POST ['password'] )) {
        $password = $_POST ['password'];
    } 
    if (isset ( $_POST ['confirm_password'] )) {
        $confirm_password = $_POST ['confirm_password'];
    } 
    $my_query = "select * from users where username like '$userEmail' ";
    $res = mysqli_query ( $conn, $my_query );

    if (mysqli_num_rows ( $res ) > 0) {
        echo "user exists";
    } else {
        $my_query = "INSERT INTO users (username,email,password,phonenumber) values ('$userEmail','$name','$password','$confirm_password') ";
        if ($conn->query ( $my_query ) === TRUE) {
            echo "registered successfully";
        } else {

            echo "failed" . "</br>" . $conn->error;
        }
    }

}else{
    echo "hiii";
}
?></div>


提交后-重定向用户。如@u_mulder所说,将用户重定向到同一页面。您可以使用标题('Location:/')执行此操作;功能。当心在调用header()函数并将其发送到header('Location:/')之前不要输出任何数据;echo“注册成功”后;如果要显示成功消息,只需创建会话并显示成功消息message@dass您的代码将失败。引用php手册“记住,在发送任何实际输出之前,必须调用header(),无论是通过普通HTML标记、文件中的空行还是从php。”是的,我知道不会显示回显。提交后-重定向用户。如@u_mulder所说,将用户重定向到同一页面。您可以使用标题('Location:/')执行此操作;功能。当心在调用header()函数并将其发送到header('Location:/')之前不要输出任何数据;echo“注册成功”后;如果要显示成功消息,只需创建会话并显示成功消息message@dass您的代码将失败。引用php手册“记住,在发送任何实际输出之前必须调用header(),无论是通过普通HTML标记、文件中的空行还是从php。”是的,我知道不会显示回显。