0

My question is that first i need to create the 10 checkboxes which i have already done and then when i set the value of any of the checkboxes as checked, it should be saved in a session after clicking on the submit button.After clicking on the submit button the values of the checkboxes that were checked should remain checked and should not be reset.And then after checking the values of checkboxes time and again on clicking on submit button, the checked values should be saved in session again such that the duplicate values are not allowed in the session. Since i am novice in php i have tried a lot but without success,

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by diafol
0
<?php
$total = (isset($_POST['mycheck'])) ? array_sum($_POST['check10']) : 0;
$output = "";
$label = array("item 1","prize 2"," fallow 3"," round 4","prism 5","echo 6"," tango 7","ent 8","thorn 9"," elbow 10");
for($x=0;$x<count($label);$x++){
	$bt = pow(2,$x);
	$chk = ($total & $bt) ? ' checked="checked"' : '';
	$output .= "<input id=\"item_$x\" type=\"checkbox\" name=\"mycheck[]\" value=\"$bt\"$chk /> <label for=\"item_$x\">{$label[$x]}</label>\n";
}
?>

and

<form method="post">
<?php echo $output;?>
<input type="submit" value="sub" />
</form>

You could save to session too:

if($total)$_SESSION['form_total'] = $total;

remember the

session_start()

Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.