简体   繁体   English

重新加载页面重新提交表单(PHP)

[英]Reloading a page resubmits form (PHP)

So when I fill in a form, and I submit the form, if I reload the page, it resubmits the form. 因此,当我填写表单并提交表单时,如果我重新加载页面,它会重新提交表单。 Here is my code: 这是我的代码:

Top of the page: 页面顶部:

    include_once "connect.php";

        $kickErrorMessage = "Please fill in all the fields.";
        $banErrorMessage = "Please fill in all the fields.";



if(isset($_SESSION['user_id']) && isset($_SESSION['email']) &&           isset($_SESSION['password']) && isset($_SESSION['rank'])) {
            if(isset($_POST['banUsername']) && isset($_POST['banReason']) && isset($_POST['banEvidence']) && isset($_POST['banDuration']) && isset($_POST['banSubmit'])) {

                $email = $_SESSION['email'];
                $punisherId = $_SESSION['user_id'];

                $username = $mysqli->real_escape_string($_POST['banUsername']);
                $reason = $mysqli->real_escape_string($_POST['banReason']);
                $evidence = $mysqli->real_escape_string($_POST['banEvidence']);

                //Etc...

I've also tried to unset the values at the end of the code but that doesn't seem to work either. 我也尝试在代码末尾取消设置值,但这似乎也不起作用。 I've also tried the array_key_set (Or whatever it's called) instead of isset, but that doesn't seem to work either. 我也尝试过array_key_set(或者不管它叫什么)而不是isset,但这似乎也没有用。

            unset($_POST['banSubmit']);
            unset($_POST['banUsername']);
            unset($_POST['banReason']);
            unset($_POST['banEvidence']);
            unset($_POST['banDuration']);

Here is my form in HTML which is on the same page as my PHP code. 这是我在HTML中的表单,它与我的PHP代码在同一页面上。 I just can't understand why it's not working. 我只是无法理解为什么它不起作用。

<form style="width: 80%;" id="banPlayer" method="post">
<p id="error"><?php echo $banErrorMessage; ?></p>
                Username: <input type="text" name="banUsername"><br>
                Reason: <textarea name="banReason"></textarea><br>
                Evidence: <input type="text" name="banEvidence"><br>

                Duration: <select name="banDuration" style="margin-bottom: 30px;">
                    <option value="oneDay">1 Day</option>
                    <option value="twoDay">2 Days</option>
                    <option value="threeDay">3 Days</option>
                    <option value="fourDay">4 Days</option>
                    <option value="fiveDay">5 Days</option>
                    <option value="sixDay">6 Days</option>
                    <option value="oneWeek">1 Week</option>
                    <option value="twoWeek">2 Weeks</option>
                    <option value="threeWeek">3 Weeks</option>
                    <option value="oneMonth">1 Month</option>
                    <option value="twoMonth">2 Months</option>
                    <option value="threeMonth">3 Months</option>
                    <option value="fourMonth">4 Months</option>
                    <option value="fiveMonth">5 Months</option>
                    <option value="sixMonth">6 Months</option>
                    <option value="sevenMonth">7 Months</option>
                    <option value="eightMonth">8 Months</option>
                    <option value="nineMonth">9 Months</option>
                    <option value="tenMonth">10 Months</option>
                    <option value="elevenMonth">11 Months</option>
                    <option value="oneYear">1 year</option>
                    <option value="permanent">Permanent</option>
                </select>



<span style="margin-left: 4%; margin-top: 60px;">
                <a class="button" onClick="showPunishmentWarning();" href="#">Terms and conditions</a>
                <a class="button" onClick="showHelpScreen();" href="#">Help! I incorrectly punished someone!</a>
            </span>

            <input style="margin-top: -8px;" type="submit" value="Ban Player" name="banSubmit">


        </form>

I'm hoping someone else can spot my error. 我希望别人能发现我的错误。 I have no idea what's happening here. 我不知道这里发生了什么。

onclick="return confirm('Confirm submit?')"除非得到确认,否则不会提交表格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM