checkbox array not updating correct records in mysql/php
<p>i have a form that contains a table which is dynamically created from an mysql query. </p>

<p>Each row contains a persons name and a checkbox. what i am trying to do is have the persons record updated with a 1 if the checkbox is checked or 0 if it is unchecked.</p>

<p>The problem is that when i use the below code, the right number of records are updated but not for the right person.
here is the relevant form code:</p>

<pre><code>&lt;?php
while ($row = mysqli_fetch_array($queryresult,MYSQLI_ASSOC)) {
echo '
        &lt;tr&gt;
            &lt;td align="left"&gt;'. ucfirst($row['CustNumber']) .'&lt;/td&gt;
            &lt;td align="left"&gt;'. ucfirst($row['Firstname']) .' '. ucfirst($row['Surname']) .'&lt;/td&gt;
            &lt;td align="center"&gt;
                &lt;input type="hidden" name="cid[]"  value="'. $row['CustNumber'] .'"&gt;
                &lt;input type="hidden" name="cbox[]"  value=""&gt;
                &lt;input type="checkbox" name="cbox[]"  value="1"&gt;
            &lt;/td&gt;   
        &lt;/tr&gt;';
}
</code></pre>

<p>and here is a simplified processing page:</p>

<pre><code>    foreach ($_POST['cid'] as $key=&gt;$custid) {
    $check = $_POST['cbox'][$key];
        if ($check == "1") {
            $update ="UPDATE customer SET Active = '1' where CustID = '$custid'";
            $updatequery = mysqli_query($con,$update);
        } 
        else {
            $update ="UPDATE customer SET Active = '0' where CustID = '$custid'";
            $updatequery = mysqli_query($con,$update);
        }
    }
</code></pre>

<p>can some tell me where i am going wrong? feel like I'm close but cant put it all together.</p>

<p>UPDATE:
changing :</p>

<pre><code>&lt;td align="center"&gt;
            &lt;input type="hidden" name="cid[]"  value="'. $row['CustNumber'] .'"&gt;
            &lt;input type="hidden" name="cbox[]"  value=""&gt;
            &lt;input type="checkbox" name="cbox[]"  value="1"&gt;
        &lt;/td&gt;   
</code></pre>

<p>to:</p>

<pre><code>&lt;td align="center"&gt;
         &lt;input type="hidden" name="cid['. $row['CustID'] .']"  value="'. $row['CustID'] .'"&gt;
         &lt;input type="checkbox" name="cbox['. $row['CustID'] .']"  value="1"'&gt;
        &lt;/td&gt;
</code></pre>

<p>has solved the issue, as per showdev's comment.Thanks</p>