Hi all,

Still struggling a bit with PHP here. I wrote a script a while back that performs a display of various files from a folder. In this script, I have a piece of code that determines whether or not the signed in user is an admin or a user. If admin then it displays an upload form to add more files to the folder, else, no upload form. In the list I would now like to add a delete function the will be displayed for the admin only so that he/she may delete a file from the folder. I am really not sure where to handle this function and would appreciate any help here.

Here is what I have now:

$manager_y = mysql_query("SELECT manager FROM login WHERE user_id='$logged_user_id' AND manager='y'");
     $status = mysql_fetch_array($manager_y);

function dirDisplay($path="forms") {  
     $fileList = array();
     while ($file = readdir($TrackDir)) {  
     	if ($file != "." && $file != "..") {
	 foreach ($fileList as $value) {
	if($status) {
		 echo "<tr><td><input type=\"submit\" name=\"delete\" value=\"Delete\"><a href=forms/$value target=blank>$value.</a><br /></td></tr>";
	else {
	 echo "<tr><td><li><a href=forms/$value target=blank>$value.</a><br /></li></td></tr>";


Thanks in advance for any help on this...

7 Years
Discussion Span
Last Post by sandeepji1

hi phaedrusGhost,
You may use javascript.I am giving logic.
1)create one function in javascript it will have one argument

  function takeAction(int action)
      if (action==0)
            //Add button event or action
       else if (action==1)
            //delete button event or action


2)If I am not wrong You have button name add and delete. You call takeAction(int action) this fucntion ont these button click event with proper parameter.Add button parameter should be different from Delete button parameter.

I have consider parameter value 0 for Add button event
and 1 for delete button.

If you have any doubt please let me know.


Edited by Nick Evan: Fixed formatting


Thanks for the feedback Arun but I would like to have a button next to each file. Once the button is pressed i will use a "are you sure?" javascript function.


Hi Dear,
I did not get you what you said
"but I would like to have a button next to each file. Once the button is pressed i will use a "are you sure?" javascript function."


Hi Arun,

The way I see this happening is to have a delete button next to each file for the admin to use as they wish. Once the "delete" button is clicked, a basic javascript function will show asking if they are sure they want to continue with the deletion process and a yes or no button.

Hope this makes sense.

Thanks again for the help...


Hi, I here mention just the point you need means how we perform the two operation together.

/* fetch tha data like that
/ Now, We Perform Saving Operation.
                if(isset($_POST['dir_save']) == 'Save')
                    $query=mysql_query("INSERT INTO dir_registration(attribute1,attrrbute2)                           VALUES('$name','$value2')",$connect);

// Now We Perform Search Operation.     

                    $query=mysql_query("SELECT * FROM dir_registration WHERE name = ?  ,$connect);
                    while($row = mysql_fetch_array($query))


//Now We Perform Deletion Operation

                if(isset($_POST['dir_delete']) == 'Delete')

                    $query = mysql_query("DELETE FROM dir_registration WHERE name= ? ",$connect);
<form name="registration_dir" method="post" action="registration_dir.php">
<input type="hidden" name="posted" value="true");
<input type="submit" name="dir_save" value="Save">
<input type="submit" name="dir_delete" value="Delete" />
<input type="submit" name="dir_delete" value="Delete" />

the data on which you want to process.... 
<b>Name :</b><input type="text" name="dir_name" value=" " size="38">

Edited by Reverend Jim: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.