Kieron Wiltshire
Kieron Wiltshire

Reputation: 81

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.

            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. 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.

Upvotes: 0

Views: 139

Answers (1)

bcr
bcr

Reputation: 3811

onclick="return confirm('Confirm submit?')" will not submit the form unless confirmed.

Upvotes: 2

Related Questions