Reputation: 41
I am storing a radio button value which can be true, false or NULL in a database. In case of null or false the answer is 0 that is false. Is there any solution for checking the null value? I have tried using isset and Empty but none of these help. Database is MSSQL and datatype is bit to store the value of radio button
<input name="radioVal" type="radio" id="radioVal" value="false"
<?PHP
if(row['radioVal'] == false )
echo "checked='checked' ";
}
?> />
<input name="radioVal" type="radio" id="radioVal" value="true"
<?PHP
if(row['radioVal'] == true )
echo "checked='checked' ";
}
?> />
Upvotes: 4
Views: 163
Reputation: 238
Maybe you should use another data type in your SQL Database.
I suggest Enum or something like that:
ENUM('false', 'true', 'NULL')
In your PHP file you
<?PHP
if(row['radioVal'] == false )
echo "checked='checked' ";
}
?>
Upvotes: 0
Reputation: 162831
The bit column is probably going to be represented as a 1
or a 0
. Use the triple equals to check for value and type. Check if row['radioVal'] === 1
for true, row['radioVal'] === 0
for false, and row['radioVal'] === null
for null.
Upvotes: 1