i have written a very simple script for updating multiple values in different columns.
My issue is that when i try to update values in columns it work fine, but in case of check box the values are inserting incorrectly.

for ex . if i have 7 rows to update and in selection option i select 1 , 2 , 3 check box and i don't select 4 5 and again select 6 7 then on updating it take select for 1 , 2 , 3 ,4 ,5 and leaving 6 7 unselected

i am pasting my codes here

form

```
     <?php include("db.php");

          $id = $_GET['id'];
   $tDate2=$_GET['tDate2'];
 ?> <form method="POST" style="width:50%" action="updatemonthly.php"  >
  <table id="rounded-corner">

    <?php
    $conn=mysql_connect("localhost","root","root") or die(mysql_error());
    mysql_select_db("monthly_pmc_admin") or die(mysql_error()); 
     $result1 = mysql_query("SELECT * from project_details where id ='$id' ;");
     $row = mysql_fetch_assoc($result1);
     $pno=$row['Project_No'];
    $result = mysql_query("SELECT * from capex_phasing_data where Project_Number ='$pno' order by id ;");
     ?>
    <thead>
      <tr>
        <th colspan="6" scope="col" class="rounded-company">Edit/ Delete Capex Graph Values</th>
        <th scope="col" class="rounded-q1"> <?php echo $tProjNo ?></th>
        <th scope="col" class="rounded-q4"></th>
      </tr>
    </thead>
    <tfoot>
      <tr>
        <td colspan="7" class="rounded-foot-left" align="center"><input type="submit" name="submit" value="DELETE" id='myButton1' />
          <input type="submit" name="submit" value="UPDATE" id='myButton1' />
         <?php 
         echo 
          '<a href="../capex.php?id=' . $id . '&tDate2='.$tDate2.'"> Add New Capex Value</a>';
          ?></td>
        <td class="rounded-foot-right"></td>
      </tr>
       <tr>
            <td colspan="4" class="rounded-foot-left" align="center"> <?php 
            echo('<A hREF="http://10.26.162.84/graph1/default.aspx?id='.$pno .'&tDate2='. $tDate2. '" target="_blank"> View Graph </A>');?></td>
            <td class="rounded-foot-right"></td>
          </tr>
    </tfoot>
    <tr>
      <th align='center'> Select to <br/>
        Delete Record </th>
      <th >Month</th>
      <th>Planned Phasing </th>
      <th>Actual Phasing </th>
       <th>Select To Display Value in Graph</th>

    </tr>
    <?
    for($i=1;$i<=mysql_num_rows($result);$i++) {
    $row = mysql_fetch_assoc($result);
    ?>
    <tr>
      <td align='left' ><input  type="checkbox" name="chk[]"  value="<?=$row['id']?>" align='center' />
      </td>
      <td align='left'><input type="text" name="month[]" size="10" id="jj" value="<?php echo $row['Month'];?>"  />
      </td>
      <td align='center' ><input name="planman1[]"  size="50" type="text" id="rr" value="<?php echo $row['Planned_Phasing'];?>"  />
      </td>
      <td align='center' ><input name="planman2[]" type="text" size="8" id="r1r" value="<?php echo $row['Actual_Phasing'];?>"  />
      </td>

      <td align='center' ><input name="planman5[]" type="checkbox" id="r4r"  <? if($row['Select_project']==1) {echo 'checked';} ?>  />
      </td>

        <input  type="hidden" name="rowid[]"  value="<?=$row['id']?>" align='center' />
        <input type="hidden" name="ProjNo" value="<?php echo $id; ?>">
          <input type="hidden" name="tDate2" value="<?php echo $tDate2; ?>">
        <!--<input type="hidden" name="ProjNo" value="<?php echo $tProjNo; ?>">-->
      </td>
    </tr>
    <?php
     }
     ?>

```

update query

```
<?php
session_start();
require_once('dbclass/database.php');
$myClass=new database();
//echo $_POST['name'];
  $array=$_POST['rowid'];
  $month=$_POST['month'];
  $planman1=$_POST['planman1'];
  $planman2=$_POST['planman2'];
  $planman3=$_POST['planman3'];
  $planman4=$_POST['planman4'];
  $planman5=$_POST['planman5'];
  $actuanman=$_POST['actuanman'];
  $length=count($_POST['rowid']);
  $chk=$_POST['chk'];
  $projno=$_POST['ProjNo'];
  $tDate2=$_POST['tDate2'];

  if($_POST['submit']=='UPDATE'){

for($a=0;$a<$length;$a++){
    $rid=$array[$a];
   $array[$a];
   $month[$a];
   $planman1[$a];
   $planman2[$a];
   $planman3[$a];
   $planman4[$a];
   $planman5[$a];
   $ac= $actuanman[$a];

 if($ac=='on'){$ch=1;} else {$ch=0;}

 if($planman5[$a]=='on'){$planman5[$a]='1';} else {$planman5[$a]='0';}

 $sql="UPDATE  capex_phasing_data set   Month='".$month[$a]."',   Planned_Phasing='".$planman1[$a]."' , Actual_Phasing='".$planman2[$a]."',    Select_project='".$planman5[$a]."' where id='".$rid."'";

mysql_query($sql) or die(); 

header("location:#");
}

}

```