title: unable to delete from database with php
body: <p>Data is not being deleted from the database. I can add and view.</p>
  
  <p>If I put <code>print_r($submissions);</code> I can see my data. E.g. <code>Array ( [0] =&gt; 2 )</code> The <code>$count++;</code> is always displaying <code>0</code> unless I put the count outside of the if statement. The <code>echo "we got an error &lt;br&gt;";</code> will show as many times as there are submissions to be removed. I tested the SQL query and that works fine. Not sure where to go with this now so any help appreciated. Related code below:</p>
  
  <p>Model:</p>
  
  <pre><code>function deleteSubmission($conn,$submission_id)
  {
      $query = "DELETE FROM submissions WHERE submission_id=:submission_id";
      $stmt = $conn-&gt;prepare($query);
          $stmt-&gt;bindValue(':submission_id',$submission_id);
      $affected_rows = $stmt-&gt;execute();
      if($affected_rows==1)
      {
              //echo $affected_rows;
              echo ($affected_rows) ? "true" : "false";
              echo " working ";
          return true;
      }else{
          //echo $affected_rows;
              echo ($affected_rows) ? "true" : "false";
              echo " not working ";   
              return false;
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>//they didn't submit the form
  if(!isset($_POST["deleteSubmissionsBtn"]))
  {
      header("Location:all-submissions-delete.php");
      exit;
  }
  
  $msg;
  //validate
  if(isset($_POST['submissions']))
  {
      $submissions=$_POST['submissions'];
      $conn=getConn();
      $count=0;
      foreach ($submissions as $submission_id) 
      {   
  
  
          if(deleteSubmission($conn,$submission_id))
          {
              $count++;
          }
                  else{
                      echo "we got an error &lt;br&gt;";
                  }
  
      }
          print_r($submissions); 
          //echo $submission_id;
  
      $conn=NULL;
      $msg="Successfully deleted $count submissions";
  }else{
      $msg="You need to select some submissions to delete";
  }
  
  include("views/delete-feedback-view.php")
  
  ?&gt;
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>echo "&lt;form action='delete-submissions.php' method='POST'&gt;";
  foreach($allSubmissions as $submission)
  {
      echo "&lt;div&gt;";
      echo "&lt;label&gt;".$submission-&gt;title."&lt;/label&gt;";
      echo "&lt;input type='checkbox' value='".$submission-&gt;submission_id."' name='submissions[]'/&gt;";
      echo "&lt;/div&gt;";
  }
  echo "&lt;input type='submit' name='deleteSubmissionsBtn' value='delete submissions'&gt;";
  echo "&lt;/form&gt;";
  </code></pre>