title: How do I delete files from dir plus db
body: <p>So this is how I tried an put them together
  But deleting the file in dir needs a value in the name of checkbox and deleting the row in db doesn't...</p>
  
  <pre><code>if(isset($_POST['delete']) &amp;&amp; isset($_POST['checkbox'])){       
  
      $checkbox = $_POST['checkbox'];
  for($i=0;$i&lt;count($checkbox);$i++){
      $del_id = $checkbox[$i];
      $sql = "DELETE FROM media WHERE id='$del_id'";
      $result = mysqli_query($connection, $sql);
      }
  foreach($_POST['checkbox'] as $key =&gt; $value){
      $name = $key;
      list($dir, $file_name_type) = explode("/",$name);   // get actual file name
      $actual_name = $file_name_type;
      list($actual_name,$type) = explode(".",$file_name_type);
  if(unlink($key) &amp;&amp; $result){
      $_SESSION["message"]="Datei &lt;b style=\"color:#005577\"&gt; &amp;nbsp; ".$actual_name."&lt;/b&gt;  &amp;nbsp; wurde erfolgreich gel&amp;ouml;scht :)";
      header ("Location: media.php");
      } else {
          $_SESSION["message"]="Datei &lt;b style=\"color:#005577\"&gt; &amp;nbsp; ".$actual_name."&lt;/b&gt;  &amp;nbsp; konnte nicht gel&amp;ouml;scht werden.";}
      header ("Location: media.php");
      }
  }
  $result = mysqli_query($connection, "SELECT * FROM media ORDER BY date DESC");
  confirm_query($result);
  
  while ($row = mysqli_fetch_array($result)){
      $post_date = new DateTime($row["date"]);
  
  echo "
      &lt;tr&gt;
          &lt;td&gt;&lt;input name=\"checkbox[]\" type=\"checkbox\" value=" .$row['id']. "&gt;
          &lt;td&gt;&lt;a class=\"image\" href=" .$row['path']. " rel=\"lightbox\"&gt;&lt;img src=" .$row["path"]. " height=\"50\"&gt;&lt;/a&gt;&lt;/td&gt;
          &lt;td class=\"title\"&gt;" .$row['file_name']. "&lt;/td&gt;
          &lt;td class=\"date\"&gt;".strftime("%e. %b, '%g", $post_date-&gt;getTimestamp())."&lt;/td&gt;
      &lt;/tr&gt;";
  }
  ?&gt;
  &lt;/table&gt;
  &lt;/form&gt; 
  </code></pre>
  
  <p>Cheers Chris</p>