By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,186 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

Removing files into a MySQL database using PHP

P: 9
Hi,

First off I am self learning PHP and MYSQL, which I saw your guide on "Uploading files into a MySQL database using PHP" and this was great guide and responses that had came through.

My question is how do I now remove files from the guide that you have created above,

thanks
Mar 14 '12 #1
Share this Question
Share on Google+
12 Replies


Dormilich
Expert Mod 5K+
P: 8,639
delete them from the database (using a DELETE query and passing the PK).
Mar 15 '12 #2

P: 9
Hi Dormilich,
Sorry is PK the primary key?

how would I go about this as I was thinking to create the delete file that is linked in the list_files.php so that when open I can then view the files that I want to download or delete.

thanks for the reply
Mar 15 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
Sorry is PK the primary key?
correct.

the delete file should do just this, delete the chosen entry from the DB.
all you need in the list_files.php is a link/form that calls the delete script passing it the ID (PK) of the file to be deleted.
Mar 15 '12 #4

P: 9
Hi again,

I already have linked the delete_file.php to the list_files.php

as for the delete page the code I have done is this:

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $dbLink = new mysqli('', '', '', '');
  3. if(mysqli_connect_errno()) {
  4. die("MySQL connection failed: ". mysqli_connect_error());
  5.  
  6. $query = "DELETE FROM file WHERE id = ('$id')"; 
  7.  
  8. $result = mysql_query($query); 
  9.  
  10. echo "The data has been deleted."; 
  11. ?>  
which this code said it has deleted but I can still see it on my list files and my database.

thanks for the reply
Mar 15 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
compare lines #2 and #9. doesn't anything jump to the eye?

PS. enable error reporting/display.
Mar 15 '12 #6

P: 9
in line two I added have my details and connects to the database, in line nine it executes the query? and finally, how do i enable reporting/display as I am using dreamweaver CS5.5 and PHPMYADMIN
Mar 15 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
in line two I added have my details and connects to the database, in line nine it executes the query?
and now compare what you have written.

and finally, how do i enable reporting/display
this way. and in the runtime configuration.
Mar 15 '12 #8

P: 9
Hi,

I am still having the same problem and there is no error detected as far as my friend and has found out for me.

I don't want to be a burden but could you provide the code with comments so that I can understand it and also see where I went wrong please

e.g. I have notice that in line nine I left out the "i" in "mysql_query" however I though this will be the same way as the get_file.php but it removes it.
Mar 15 '12 #9

Dormilich
Expert Mod 5K+
P: 8,639
e.g. I have notice that in line nine I left out the "i" in "mysql_query" however I though this will be the same way as the get_file.php but it removes it.
what get_file.php? (note: I check against Atli's original post)

and that is exactly the point where you have the problem. the mysql extension is in no way compatible to the mysqli extension (though they share a similar, but distinct syntax), i.e. you can't expect mysql run from mysqli (and vice versa). and not having a mysql connection open certainly causes an error when trying to use mysql_query().
Mar 15 '12 #10

P: 9
Hi,

what I had done is that I made an error on the extension now corrected.

what I want to achieve is that from Atli's post he had done:

form - to upload file
add_file.php - that adds the file to the database
list_files.php - to view the list of files and to download the file
get_file.php - is to gather the data shown in list_files.php

what I want to do is also to include in list_files.php is to delete file.
Mar 15 '12 #11

P: 9
as you can see in phase three line 37 get_file.php is stated
Mar 15 '12 #12

P: 9
Hi again,

I was looking at the list-files.php and I was wondering that the headers bring the data forward could i then use "unlink" to remove the file from the database or I did not understand the download phase.
Mar 15 '12 #13

Post your reply

Sign in to post your reply or Sign up for a free account.