我尝试了许多不同的方法,但我似乎无法弄清楚为什么提交按钮在第一次单击时不起作用。我已经从代码中删除了 if 语句,但仍然需要单击两次。在第一次单击时,它会刷新页面,当您单击必须向下滚动到的提交按钮时,这是最明显的。下面的代码在页面上重复了大约 27 次,但歌曲不同。在第二次点击后它们都可以工作,所以我很确定它们连接正确。此外,当您单击按钮一次,然后如果您单击另一个按钮,它会提交您单击的第一个按钮。
如果有人想看看它的实际外观,我已经在页面上设置了一个测试帐户。http://www.saint57records.com/rewards/index.php用户名:test 密码:test
<?php
$resultstwo = mysqli_query($con,"Select * FROM users WHERE user_name ='$username'");
while ($row = mysqli_fetch_array($resultstwo))
{
extract($row);
}
?>
<form method="post" action="index.php">
<?php
//If submit form was clicked
if(isset($_POST['endo'])) {
//Server side validation for security purposes
if($points >= 100 AND $endo == 0 AND $savetheworldalbum == 0) {
mysqli_query($con,"UPDATE users SET points = points - 100 WHERE users.user_name = '$username' LIMIT 1");
mysqli_query($con,"UPDATE users SET endo = 1 WHERE users.user_name = '$username' LIMIT 1");
}
}
if ($points >= 100 AND $endo == 0 AND $savetheworldalbum == 0) {
echo '<input type="submit" name="endo" value="100pts">';
} elseif ($endo == 1 OR $savetheworldalbum == 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">';
}
?>
</form>
这就是输出
<form method="post" action="index.php">
<input type="submit" name="endo" value="100pts"></form>