I am using PHP and MySQL to create a drop box system. The problem I am facing is that I need to delete a folder and delete all the folders and files inside it. It works fine with two folders but when I have 3 folders it does not delete them. Below is the code in PHP. please help me.

```
<?php
session_start(); 
require 'connection.php';
$folderid = $_GET['folderid'];

function rrmdir($dir) {  
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
  if ($object != "." && $object != "..") {
    if (filetype($dir."/".$object) == "dir") 
       rrmdir($dir."/".$object); 
    else unlink   ($dir."/".$object);
  }
}
reset($objects);
rmdir($dir);
 }
  $delete = mysql_query("DELETE FROM file WHERE id='$folderid'");
}

if($folderid != ""){
$result = mysql_query("SELECT file.path FROM ftpdb.file WHERE ftpdb.file.fileID =         $folderid");
$qry = mysql_fetch_assoc($result);
$dir = $qry['path'];
//Calls a function which deletes all the files and folder in a pathy specified above
rrmdir($dir);
//Delete From database files and folders if the folderID is not null 
$delete = mysql_query("DELETE FROM file WHERE fileID='$folderid' OR parentFolder = '$folderid'");
$deleteFiles = mysql_query("DELETE FROM file_files WHERE folder_id = '$folderid'");
$_SESSION['error'] = "Folder has been deleted";
header("location: client.php");
}else{
$_SESSION['error'] = "Error occured please try again";
header("location: client.php");
}
?>

```

This is the database I have managed to delete test folder when I delete home but not testing which is in tests. I think that the sql statement is incorrect
![The database is shown in the image below](https://i.stack.imgur.com/RxD5V.gif)