每次点击提交按钮两次以获取代码时,也只是随机触发不同的代码,这些代码的设置方式相同,但输入的名称和$_POST
内的名称不同。我是否通过将输入的名称设置为相同的东西来使用$_POST
权限?
这是代码
<?php
//If submit form was clicked
if(isset($_POST['intro'])) {
//Server side validation for security purposes
if($userpoints >= 100 AND $intro == 0 AND $lifeonmarsalbum == 0) {
mysqli_query($con,"UPDATE users SET points = points - 100 WHERE users.user_name = '$username' LIMIT 1");
mysqli_query($con,"UPDATE users SET intro = 1 WHERE users.user_name = '$username' LIMIT 1");
}
}
?>
<form method="post" action="index.php">
<?php
if ($userpoints >= 100 AND $intro == 0 AND $lifeonmarsalbum == 0) {
echo '<input type="submit" name="intro" value="100pts">';
} elseif ($intro == 1 OR $lifeonmarsalbum == 1) {
echo '<input type="submit" name="submit" value="100pts" disabled title="You already earned this track!">';
} else {
echo '<input type="submit" name="submit" value="100pts" disabled title="You need at least 100 points for this download">';
}
?>
答案 0 :(得分:2)
只有在满足name="intro"
条款的第一行时才输出if()
提交按钮。很可能在您第一次加载此页面时,不满足该条件,因此没有intro
按钮。在第一次提交后,条件符合,并且您在表单中获得name="intro"
,然后提交“开始”工作。