Removing files into a MySQL database using PHP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aziz123
    New Member
    • Mar 2012
    • 9

    Removing files into a MySQL database using PHP

    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
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    delete them from the database (using a DELETE query and passing the PK).

    Comment

    • aziz123
      New Member
      • Mar 2012
      • 9

      #3
      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

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        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.

        Comment

        • aziz123
          New Member
          • Mar 2012
          • 9

          #5
          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:

          Code:
          <?php 
          $dbLink = new mysqli('', '', '', '');
          if(mysqli_connect_errno()) {
          die("MySQL connection failed: ". mysqli_connect_error());
          } 
          
          $query = "DELETE FROM file WHERE id = ('$id')"; 
          
          $result = mysql_query($query); 
          
          echo "The data has been deleted."; 
          ?>
          which this code said it has deleted but I can still see it on my list files and my database.

          thanks for the reply
          Last edited by Dormilich; Mar 15 '12, 01:40 PM. Reason: Please use [CODE] [/CODE] tags when posting code.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            compare lines #2 and #9. doesn't anything jump to the eye?

            PS. enable error reporting/display.

            Comment

            • aziz123
              New Member
              • Mar 2012
              • 9

              #7
              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

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                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.

                Comment

                • aziz123
                  New Member
                  • Mar 2012
                  • 9

                  #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_quer y" however I though this will be the same way as the get_file.php but it removes it.

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    e.g. I have notice that in line nine I left out the "i" in "mysql_quer y" 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().

                    Comment

                    • aziz123
                      New Member
                      • Mar 2012
                      • 9

                      #11
                      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.

                      Comment

                      • aziz123
                        New Member
                        • Mar 2012
                        • 9

                        #12
                        as you can see in phase three line 37 get_file.php is stated

                        Comment

                        • aziz123
                          New Member
                          • Mar 2012
                          • 9

                          #13
                          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.

                          Comment

                          Working...