【发布时间】:2015-03-24 04:21:12
【问题描述】:
我有一个表单中的复选框,我需要根据数据库中的值禁用它。我搜索了很多,但找不到任何有效的解决方案。这是示例代码:
<?php
$server_name='localhost';
$username='root';
$password='';
$db_name='checkbox';
$con= mysqli_connect($server_name, $username, $password, $db_name);
if(mysqli_connect_errno())
{
echo 'Failed..!!'.mysqli_connect_errno();
}
$result= mysqli_query($con, "SELECT * FROM checkbox WHERE status=1");
$display = (mysqli_num_rows($result) == 1);
$disable = $display?'':'disabled="disabled"';
?>
<html>
<body>
<form name="f1" method="post" action="test2.php">
<input type="checkbox" name="A" value="" <?php echo $disable; ?> />
</form>
</body>
</html>
提前致谢。
【问题讨论】:
标签: php html mysql forms checkbox