即使在数据库中更改了复选框状态后,也无法禁用复选框

时间:2016-08-02 04:41:23

标签: php mysql

我的问题是,在我的复选框状态更改为0后,我无法禁用该复选框。 这是我的代码:

<body> 
<?php
$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

$username = $_POST['username'];
if(isset($_POST['Next']))
{   
foreach($_POST['boxs'] as $f => $value){
    $sql = "UPDATE box SET status = '1' WHERE boxid = '$value'";
    mysqli_query($con,$sql) or die(mysqli_error($con));

$result = "INSERT INTO booked(username, boxid) VALUES('$username', '$value')";
    mysqli_query($con,$result) or die(mysqli_error($con));
   }

}
?>

</body>

我的数据库复选框状态已更改,但对复选框没有任何影响。复选框仍处于启用状态。除此之外,对于INSERT查询,用户名无法插入表中,只输入空值。我怎样才能解决这两个问题?

0 个答案:

没有答案