title: Using a SQL update in a foreach loop php
body: <p>I am trying to update a table with multiple checkbox. Each row has a checkbox.
  I want to change value of column <strong>status</strong> by setting 1 instead of 0 if the checkbox is checked.
  Below is an example of the way the form is laid out:</p>
  <pre><code>&lt;tbody&gt;
  &lt;?php
      foreach ($result as $key =&gt; $value) {
    ?&gt; 
  &lt;?php echo &quot;&lt;td class='form-group form-md-line-input'&gt;  &lt;input type='checkbox' name='formation[]' id='myFormation[]' class='form-check-input' &gt;&lt;/td&gt;&quot; ?&gt;
  &lt;?php echo &quot;&lt;td class='form-group form-md-line-input'&gt;  &lt;input class='form-control' type='text' name='status' value='0'&gt; &lt;/td&gt;&quot; ?&gt;
  &lt;/tbody&gt;
  </code></pre>
  <p>An example of the way the query is laid out:</p>
  <pre><code>// update the product
   function update(){
  
      if(isset($_POST['submit'])){
  
             if(!empty($_POST['formulaire'])) {
  
           foreach($_POST['formulaire'] as $value){
                                                              
                                                              
               $query = &quot;UPDATE 
                  &quot; . $this-&gt;table_name . &quot; 
              SET 
                  Statut = 1
                    WHERE ...........;
               $stmt = $this-&gt;conn-&gt;prepare($query);
      
       $stmt-&gt;bindParam(':ID', $this-&gt;ID);
      
       // execute the query
       if($stmt-&gt;execute()){
          return true;
       }else{
          return false;
       }
                 }
  
               }
  
           }
   }
  </code></pre>
  <p>My problem is how to write the query.
  Thanks in advance</p>