1. Home
  2. Computing & Technology
  3. PHP / MySQL

Storing User Submitted Data and Files in MySQL

By Angela Bradley, About.com

7 of 7

Removing Files

Here is a very simple way of removing files from the database. You want to be careful with this one!! Save this code as remove.php

<?php
mysql_connect("your.server.com","username","password");
mysql_select_db("database_name");
$query = "DELETE FROM uploads where id=$id";
$delete = MYSQL_QUERY($query);
print "File ID $id has been removed from the database";
?>

Like our previous code that downloaded files, this script allows files to be removed just by typing in their URL: http://yoursite.com/remove.php?id=2 (replace 2 with the ID you want to remove.) For obvious reasons, you want to be careful with this code. This is of course for demonstration, when we actually build applications we will want to put in safeguards that ask the user if they are sure they want to delete, or perhaps only allow people with a password to remove files. This simple code is the base we will build on to do all of those things.

Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP with MySQL
  5. Removing file uploads to MySQL

©2009 About.com, a part of The New York Times Company.

All rights reserved.