因此,当我填写表单并提交表单时,如果我重新加载页面,它会重新提交表单。这是我的代码:
页面顶部:
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...
我还尝试在代码末尾取消设置值,但这似乎也不起作用。我也尝试过array_key_set(或者不管它叫什么)而不是isset,但这似乎也不起作用。
unset($_POST['banSubmit']);
unset($_POST['banUsername']);
unset($_POST['banReason']);
unset($_POST['banEvidence']);
unset($_POST['banDuration']);
这是我的HTML表单,它与我的PHP代码在同一页面上。我只是无法理解为什么它不起作用。
<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>
我希望别人能发现我的错误。我不知道这里发生了什么。
答案 0 :(得分:2)
onclick="return confirm('Confirm submit?')"
不会提交表单。