Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to delete a posting file

Status
Not open for further replies.

newlearner2005

Programmer
May 9, 2005
32
0
0
US
Hello Everybody

I have successfully uploaded and downloaded data files to MySQL database by using PHP scripts.
On my webpage I can "open" or "save" that file by clicking on it. Everything is fine. But I did not have a choice to delete it.
I had to write some PHP scripts as follow:
// delete the row from the database
$query = "DELETE FROM upload WHERE postId='$postId'";

$result = mysql_query( $query );

// print out the results
if( $result )
{
echo( "Successfully deleted the file." );
}
else
{
die( "Error: Could not delete file: " . mysql_error() );
}

Eventhough it said "Successfully delete the file" but I still see that file on my webpage. I checked MySQL database, it is still there.
Can anybody help me how to delete a file from MySQL database by using PHP. (I know how to delete it from MySQL command prompt)
Thank you very much.
new learner2005
 
Where is your $postId FROM?
Try this, and see whether it gives you any property sql.

$query = "DELETE FROM upload WHERE postId='$postId'";
echo $query;
 
Thank you so much WoodyRoundUp

"postId" is the column in "upload" database. I want to know who is the author of the uploaded file.

And I successfully got the author name of the file basing on "postId".

Could you help me about how to delete a file by using PHP scripts ? I really appreciate.

newlearner2005
 
I need to know more about what you want.

You say:
> I have successfully uploaded and downloaded data files to MySQL database by using PHP scripts.

Based on these:

How's the format of MySQL database?
Do you have a physical file? or you are storing the file in the Blob Format?
 
Thank you very much for your help, WoodyRoundUp. I really really appreciate.
OK, here is my plan and what I have done:

1- I want users to upload their files to my website if they want to. (I got it done very well)
2- I want users to be able to download files to their local computers. ( I got it done very well )
3- I want other users to view and know who has uploaded files ( I got done very well )

Here is the problem:
I built a webpage for each individual. If he/she has uploaded files. The file name display on the web page. (when you click on it, it open for you to read) I do not know how to do it if the user want to delete the file ? ( Only auuthor of the file can delete the file he/she uploaded )
If the result is correct, that file will be dissapear on webpages ( other users even cannot see it anymore )

Thank you so very much. I hope I would learn from you about this. I would help me a lot.
newlearner 2005



 
If that's the case, you will need to:

Find the location of the file (I guess based on the PostId in the DB).
Use the unlink function:
Usage: unlink (location of file);

Then, remove the entry from the DB.
 
I am sorry, WoodyRoundUp. I forgot to give you my database design.
The name of MySQL database is: "registration"
There are two tables in "registration" database.

Here is table "upload"
id int(11)
name varchar(60)
type varchar(60)
size int(11)
content longblob
postId int(10)
post_date datetime
PRIMARY KEY (id)

Here is table "user_info"
username varchar(50)
password varchar(255)
first_name varchar(50)
last_name varchar(50)
email varchar(50)
userId int(10)
PRIMARY KEY (userId)

I successfully set "userId" match with "postId" . That is the main point to figure it out who has uploaded file.

Thank you so so very much again.
newlearner 2005


 
Well, how about the link that you use to delete the file?
Do you use "id" or "postID' as the file reference ID?
 
Hello WoodyRoundUp,

"id" and "postId" in "upload" table are different.
"id" for recornize the unique file.
"postId" actually is "userId" of user_info" table ( because I want to know who has uploaded file, so I based on that point to figure it out )
Thank you very much.
newlearner 2005
 
I used
$query = "DELETE FROM upload WHERE postId='$postId'";

Is it correct?
newlearner 2005
 
I don't mean this, but I meant, the HTML tag that you have.
Like:
<a href="delete.php?bla bla bla">
or some other thing, probably form.

If you know what I mean?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top