Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:32:31+00:00 2026-06-17T06:32:31+00:00

I’m a beginner with php and have created a code displaying a table with

  • 0

I’m a beginner with php and have created a code displaying a table with the data concerning my users, that is in my database.
This is the code I used.

Name
Surname
Date of Birth
Town of Birth
Code
Address
E-mail
“;

while($row=mysql_fetch_array($result))

{echo"<tr>";
echo"<td>" . $row['Name'] . "</td>";
echo"<td>" . $row['Surname'] . "</td>";
echo"<td>" . $row['DateofBirth'] . "</td>";
echo"<td>" . $row['TownofBirth'] . "</td>";
echo"<td>" . $row['Code'] . "</td>";
echo"<td>" . $row['Address'] . "</td>";
echo"<td>" . $row['Email'] . "</td>";
echo'<td><a href="delete.php?id='.$row['Code'].'">Delete</a></td>';
echo"</tr>";
}
echo"</table>";
?>

I also have created a delete.php file which allows to delete users from the db by clicking on the “delete” link, but I also wanted this code to remove a folder named with the username of the user, that is situated in the current work directory. This is the code I wrote:

<?php
$con=mysql_connect("localhost","root","mypassword");
mysql_select_db("mydb",$con);
function deletedir($dirname){
    if(file_exists($dirname) && is_file($dirname)) {
        unlink($dirname);
    } elseif(is_dir($dirname)) {
        $handle=opendir($dirname);
        while(false!==($file=readdir($handle))){
            if(is_file($dirname.$file)){
                unlink($dirname.$file);
            }
        }
        $handle=closedir($handle);
        rmdir($dirname);
    }
}

if (isset($_GET['id'])) {
    $id=$_GET['id'];
    $sql=mysql_query("SELECT Username FROM Users WHERE Code='$id'");
    while($row=mysql_fetch_array($sql)) {
        $username=$row['Username'];
        deletedir($username);
    }

    $result=mysql_query("DELETE FROM Users WHERE Code='$id'") or die(mysql_error());
    header("location: index.php");
} else {
    header("location: index.php");
}

?> 

This code deletes the user from the db but it doesn’t remove the folder called $username. Please help me to understand where the error is. Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:32:32+00:00Added an answer on June 17, 2026 at 6:32 am

    I think this is your problem:

    unlink and rmdir need a full path to the files/directories to remove if the deleting script isn’t in the same directory as what you are trying to delete.

    Try adding something like this to the top of your deletedir function:

    $dir = "/opt/www/userdirs"
    $dirname = $dir . '/' . $dirname;
    

    Change “/opt/www/userdirs” to the directory where your directories to delete reside.

    And I think that you also need to change all of these:

    $dirname.$file
    

    To:

    $dirname . '/' . $file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I have a view passing on information from a database: def serve_article(request, id): served_article

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.