Help me:

<input type="checkbox" name="cd[]" checked="checked" value="1">
JAVA<br>
<input type="checkbox" name="cd[]" value="0">
PERL<br>
<input type="checkbox" name="cd[]" value="0">
PYTHON<br>
<input type="checkbox" name="cd[]" value="0">
C#<br>
<input type="checkbox" name="cd[]" checked="checked" value="1">

i want to get all value(check and uncheck). But my array show array(1,1). i need array(1,0,0,0,1). And when i checkbox is checked(change value=1). checkbox isn't checked(change value=0).

You could use many deferent approaches to that (array marks in a field name is just a quick dirty fix …) . If you fill these options from PHP then just give names relative to the data that generating them. For example cd_0 is Java … so you will know if you get cd_0 that java is checked , and after that what weren’t checked…

Try this code

<body>
<?php
if(isset($_POST['s']))
{
  
 $a=array();
 for($i=0;$i<3;$i++)
 {
 $c='c'.$i;
 if(isset($_POST[$c]))
 {
 echo "R";
 $a[$i]=1;
 }
 else
 {
  $a[$i]=0;

 
 }
 
 }
  
  print_r($a);
  
}
 
 
 
$ck="c";
$i=1;
$name=$ck;
?>
<form id="form1" name="form1" method="post" action="chk_bx.php">
  <input name="<?php echo $name.'0'; ?>" type="checkbox" id="c" value="checkbox" /> 
  ASP
  <input name="<?php echo $name.'1'; ?>" type="checkbox" id="c" value="checkbox" /> 
  JSP
  <input name="<?php echo $name.'2'; ?>" type="checkbox" id="c" value="checkbox" /> 
  PHP
  <input name="s" type="submit" />
</form>
</body>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.