如何在提交表单后检查复选框? 我尝试使用这种方法:提交POST表单后PHP会保留复选框
<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>
,但我所有的复选框会继续检查,即使我只能选择一个,这里是我的代码:
<form id="calc" action="calculator.php" method="POST" >
<b>Enter First No: <br>
<input type = "text" name="num1" value="<?php if(isset($_POST['num1'])){echo $num1;} ?>" required="required"/><br>
Enter Second No: <br>
<input type = "text" name="num2" value="<?php if(isset($_POST['num2'])){echo $num2;} ?>" required="required"/><br>
<b>Select Operation: <br>
<input type = "checkbox" name="math[]" value="Addition" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Addition<br>
<input type = "checkbox" name="math[]" value="Subtraction" <?php if(isset($_POST['math'])) echo "checked='checked'";?>/>Subtraction<br>
<input type ="submit" value="compute" name="btnsubmit"> <br>
谢谢!
请编辑您的帖子,并把您的HTML html或代码块 –
我很抱歉,我忘了把它放在支架上, ,,, Im新到这 –
可能重复[获取$ \ _ POST来自多个复选框](https://stackoverflow.com/questions/4997252/get-post-from-multiple-checkboxes) –