title: How to insert data using a checkbox inside a while loop php
body: <p>I want to add the value of a checkbox to the specific row in the database. It adds the value to the wrong rows each time. I tried adding a hidden input with a different value.</p>
  <pre><code> if (isset($_POST['save_task'])) {
                  $count=count($_POST[&quot;pro_id&quot;]);
                  
                      $query = &quot;INSERT INTO client_program_task_activities (task_id, activity_type, type_id, show_status)
                        VALUES(?,?,?,?)&quot;;
                      $stmt = mysqli_prepare($db, $query);
                     
                      mysqli_stmt_bind_param($stmt, 'ssss', $_POST['task_id'][$i], $_POST['type'][$i], $_POST['pro_id'][$i],  $_POST['show_status'][$i]);
                      for($i=0;$i&lt;$count;$i++){
                      mysqli_stmt_execute($stmt);
                  }
                   }
  
  $sql = &quot;SELECT * FROM tasks  WHERE user_id='$user_id' ORDER BY date_added DESC &quot;;
                                  $result = mysqli_query($db, $sql);
                                  $resultCheck = mysqli_num_rows($result);
                                  if ($resultCheck &gt; 0) {
                                     
                                      echo ' &lt;form action=&quot;task_day.php&quot; method=&quot;post&quot; &gt; 
                                    &lt;table &gt;
                                      &lt;tr&gt;
                                        &lt;th&gt; ADD TASK&lt;/th&gt;
                                        &lt;th&gt; TASK NAME&lt;/th&gt;
                                        &lt;th&gt;KCAL&lt;/th&gt;
                                      &lt;/tr&gt;';
                                      
                                      while ($row = mysqli_fetch_assoc($result)) {
                                           echo '&lt;input type=&quot;hidden&quot; name=&quot;task_id[]&quot; value=&quot;'; echo $task_id; echo '&quot;&gt;';
                                          echo '&lt;input type=&quot;hidden&quot; name=&quot;pro_id[]&quot; value=&quot;'.$row['pro_id']. '&quot;&gt;';
                                          echo '&lt;input type=&quot;hidden&quot; name=&quot;type[]&quot; value=&quot;test&quot;&gt;';
                                          echo '&lt;input name=show_status[] type=&quot;hidden&quot; value=&quot;0&quot;&gt;
                                                    &lt;td&gt;&lt;input name=show_status[] type=&quot;checkbox&quot; value=&quot;1&quot;&gt;&lt;/td&gt;
                                                    &lt;td&gt;'.$row['task_name'].'&lt;/td&gt;
                                                    &lt;/tr&gt;';
                                      }
                                      echo ' &lt;/table&gt;
                                 &lt;button name=&quot;save_task&quot; type=&quot;submit&quot; &gt;Save task&lt;/button&gt;
                     &lt;/form&gt;';
                                      
                                  }
                  
                  
                                  ?&gt;
  </code></pre>