i have to store all check box value of php page in boolean formate?
Muhammad
2013-05-13 03:58:44 UTC
here is scenario... i have check box and there values fetch from database when i checked someone the true value corresponding to that check box will be updated and if i refresh the page that check box must be checked.
please guys, just tel me how can i save checkbox value as true/false in database
Five answers:
anonymous
2013-05-13 04:12:38 UTC
You are better to store it in an int(1) with values of 0 for off and 1 for on. Then when you submit the page you use an update or insert query, using an if() statement first to determine the checked state of the box. if it is checked set a, maybe $checked, variable to 1, if not set it to 0.
Then :
$query = "update table_name set checkbox_field = ' ".$checked." ' where whatever.
do not leave the spaces between he single and double quotes, they are just for clarity.
When reading it back you do a similar if() to set the displayed string to :
$stored_state = " checked = 'checked' "; if it is stored as a 1,
else $stored_state = "";
then on displaying the page :
$display string = "";
anonymous
2016-03-11 02:31:12 UTC
The New York Times would have reported it if they had any real reporters. The once great newspaper has become a rag. Useful for packing and birdcages. Obama seems to pass the buck and this is a norm for him. He still blames Bush for everything and anything and that in itself is getting redundant .He is dumb as a fox. Can't ban handguns but can tax the heck out of ammo.A change has come my friends.
anonymous
2013-05-16 05:08:59 UTC
False!
D4M
2013-05-13 05:05:33 UTC
from what you said "save checkbox value as true/false in database"
function TrueFalse($ture_value)
{
if($_POST['check'])) // note check is submit name
{$array=$_POST['field']; //note field is checkbox value make sure to add []
if($array == $true_value)
{/* set it true in database */}
else{/* set it false in database */}}}
is that what you meant ?
anonymous
2014-07-17 02:05:17 UTC
difficult thing research over google or bing this could help
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.