我的问题在于,我的复选框仅在所有复选框状态为0时才被禁用。但是,在这里,我只希望禁用选中的复选框,但是当复选框的状态未全部设置为0 ,它不会被禁用。 这里是我的代码:无法禁用复选框
<?php
$username = $_SESSION['username'];
$query = "SELECT * FROM box WHERE status = 1";
$result = @mysqli_query($con, $query);
$num_rows = @mysqli_num_rows($result);
$disable = '';
if (!$num_rows) {
$disable = 'disabled="disabled"';
}
?>
<form method = "post" action = "">
<input type='checkbox' name="boxs[]" id="1.1" value ="1.1" <?php echo $disable ?>/>
<label for="1.1" class="background1"></label> <br/>
<input type='checkbox' name="boxs[]" id="1.2" value ="1.2"<?php echo $disable ?>/>
<label for="1.2" class="background2"></label>
<br/>
<input type='checkbox' name="boxs[]" id="1.3" value ="1.3"<?php echo $disable ?>/>
<label for="1.3" class="background2"></label>
<input type="submit" name="Next" id="Next" value="next" />
</form>
<?php
if(isset($_POST['Next'])) {
foreach($_POST['boxs'] as $f) {
$sql = "UPDATE box SET status = '0' WHERE boxid = '$f'";
mysqli_query($con,$sql) or die(mysqli_error($con));
$result = "INSERT INTO booked(username, boxid) VALUES('$username', '$f')";
mysqli_query($con,$result) or die(mysqli_error($con));
}
}
?>
那么,我的代码有什么问题?
我检查了您的代码。但找不到任何问题。 –
那么,你有什么想法禁用复选框? – June
我检查了你的代码。当零库时,所有的复选框将被禁用。当其他数字通过零时,复选框将被启用。我没有发现任何错误。 –