I have a checkbox in a form which I need to disable based on the value in the database. I searched a lot, but can't find any solution that works. Here's the sample code:
<?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>
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire