Checkbox and input value at same row
<p>I create a table that show the list of the medicine. And it got stock process function.</p>

<p>The problem is, if I have 3 record of data, I can only check record no 1 and no 2, if I check record no 3 (or the last record if i got so many record) I got error.</p>

<p>The thing is, if i check data 3 (or last record), the checkbox get the <code>serialno</code>, but do not get the quantity value.</p>

<p>The also a problem occurs when I register a new medicine, then I check that box to insert the value and it returns:</p>

<blockquote>
  <p>INSERT MEDICINE QUANTITY FOR CHECKED MEDICINE.</p>
</blockquote>

<p>How do I fix this problem? I have minimized the code as much I could.</p>

<p>The form:</p>

<pre><code>&lt;form method="post" action="&lt;?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;" class="form-horizontal" role="form"&gt;  
    &lt;div class="form-group"&gt;
        &lt;label class="col-sm-3 control-label no-padding-right" for="form-name"&gt; Search : &lt;/label&gt;

        &lt;div class="col-sm-9"&gt;
            &lt;span class="input-icon"&gt;
                &lt;input type="text" id="myInput" onkeyup="myFunction()" placeholder="Keyword HERE" class="col-xs-10 col-sm-12" name="search" /&gt;
                &lt;i class="ace-icon fa fa-search green"&gt;&lt;/i&gt;
            &lt;/span&gt;
        &lt;/div&gt;
    &lt;/div&gt;
    &lt;table id="myTable" class="table  table-bordered table-hover"&gt;
        &lt;thead&gt;
            &lt;tr&gt;
                &lt;th&gt;Name&lt;/th&gt;&lt;th&gt;Serial Number&lt;/th&gt;&lt;th&gt;Price&lt;/th&gt;&lt;th&gt;Current Stock&lt;/th&gt;&lt;th&gt;Action&lt;/th&gt;&lt;th&gt;Value&lt;/th&gt;
            &lt;/tr&gt;
        &lt;/thead&gt;
        &lt;tbody&gt;                                     
        &lt;?php
            $sqlTable = "SELECT * FROM medicinestock";
            $queryTable = $conn -&gt; query($sqlTable);

            if ($queryTable -&gt; num_rows &gt; 0)
            {
                while ($resultTable = $queryTable -&gt; fetch_assoc())
                {
                    $price = number_format($resultTable['price'], 2);
                    ?&gt;
                    &lt;tr&gt;
                        &lt;td&gt;&lt;?php echo $resultTable['name']; ?&gt;&lt;/td&gt;
                        &lt;td&gt;&lt;?php echo $resultTable['serialNo']; ?&gt;&lt;/td&gt;
                        &lt;td&gt;RM &lt;?php echo $price; ?&gt;&lt;/td&gt;
                        &lt;td&gt;&lt;?php echo $resultTable['quantity']; ?&gt;&lt;/td&gt;
                        &lt;td&gt;
                            &lt;div class="checkbox"&gt;
                                &lt;label&gt;
                                    &lt;input name="checkboxCheck[]" type="checkbox" class="ace" value="&lt;?php echo $resultTable['serialNo']; ?&gt;"/&gt;
                                    &lt;span class="lbl"&gt;&amp;nbsp;&amp;nbsp;Check&lt;/span&gt;
                                &lt;/label&gt;
                            &lt;/div&gt;
                        &lt;/td&gt;
                        &lt;td&gt;
                            &lt;input type="number" name="quantity[]" style="max-width:50px" /&gt;
                        &lt;/td&gt;
                    &lt;/tr&gt;
                    &lt;?php
                }
            }
            else
            {
                $err = $conn -&gt; error;
                $status = "&lt;b&gt;&lt;p&gt;&lt;font color='red'&gt;SYSTEM ERROR : $err&lt;/font&gt;&lt;/p&gt;&lt;/b&gt;";
            }
        ?&gt;
        &lt;/tbody&gt;
    &lt;/table&gt;
    &lt;div class='clearfix form-actions'&gt;
        &lt;div class='col-md-offset-3 col-md-9'&gt;
            &lt;button class='btn btn-info' type='submit'&gt;
                &lt;i class='ace-icon fa fa-check bigger-110'&gt;&lt;/i&gt;
                Finish
            &lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/form&gt;
</code></pre>

<p>The process</p>

<pre><code>if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $icnumber = $_POST['icnumber'];

    //Check if CHECKBOX checked
    if (isset($_POST['checkboxCheck']))
    {
        $quantity = $_POST['quantity'];
        $checkboxCheck = $_POST['checkboxCheck'];
        $count = count($checkboxCheck);
    }

    if ($count == 0)
    {
        $status = "&lt;font color='red'&gt;&lt;p&gt;&lt;b&gt;PLEASE CHECK AT LEAST 1 MEDICINE PRESCRIPTION&lt;/b&gt;&lt;/p&gt;&lt;/font&gt;";
    }
    else
    {   
        //Run process for each checked checkbox
        for ($i = 0; $i &lt; $count; $i++)
        {
            $serialNo = $checkboxCheck[$i];
            $value = $quantity[$i];

            if ($value == null)
            {
                $checker = FALSE;
            }
            else
            {
                $sqlPrescription = "INSERT INTO medicinecheckout (patientic, serialno, quantity, medicineout) VALUES ('$icnumber', '$serialNo', $value, NOW())";
                $queryPrescription = $conn -&gt; query($sqlPrescription);

                if ($queryPrescription == FALSE)
                {
                    $err = $conn -&gt; error;
                    $status = "&lt;b&gt;&lt;p&gt;&lt;font color='red'&gt;SYSTEM ERROR : $err&lt;/font&gt;&lt;/p&gt;&lt;/b&gt;";
                }
            }
        }
    }

    if ($checker == FALSE)
    {
        $status = "&lt;b&gt;&lt;p&gt;&lt;font color='red'&gt;INSERT MEDICINE QUANTITY FOR CHECKED MEDICINE&lt;/font&gt;&lt;/p&gt;&lt;/b&gt;";
    }
}

&lt;script type="text/javascript"&gt;
    function myFunction() 
    {
        var input, filter, table, tr, td, i;
        input = document.getElementById("myInput");
        filter = input.value.toUpperCase();
        table = document.getElementById("myTable");
        tr = table.getElementsByTagName("tr");

        // Loop through all table rows, and hide those who don't match the search query
        for (i = 0; i &lt; tr.length; i++) 
        {
            td = tr[i].getElementsByTagName("td")[0];
            if (td) 
            {
                if (td.innerHTML.toUpperCase().indexOf(filter) &gt; -1) 
                {
                    tr[i].style.display = "";
                } 
                else 
                {
                    tr[i].style.display = "none";
                }
            } 
        }
    }
&lt;/script&gt;
</code></pre>