how cant i delete relevant files from host along with mysql delete function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how cant i delete relevant files from host along with mysql delete function

    hello All,

    PHP Code:


    require('db.php');
    $id=$_REQUEST['id'];
    $query "DELETE FROM files WHERE id=$id";
    $result mysqli_query($con,$query) or die ( mysqli_error());
    header("Location: index.php"); 
    here is my php code to delete a the mysql records where id =$id

    this one record includes two files (mp3 file & jpg file) $row['path'] & $row['cover'].
    I would be very thankful if anyone can help me to find way for delete these mp3 & jpg files also from the host along with the mysql record.


    #2
    hi, your code is insecure, use:
    HTML Code:
    $query = "DELETE FROM files WHERE id=".intval($id);
    can you share the structure of your MySQL table?

    to delete from host use the unlink, i.e.
    HTML Code:
    unlink($row['path']);
    make sure that you select from files where id, then unlink and then do the delete in the database
    Advertise your mobile site for FREE with AdTwirl

    Comment


      #3
      Id , title , artist, path, cover_photo, size, date this is my structure

      Comment


        #4
        PHP Code:
        require('db.php');
        $id=$_REQUEST['id'];
        $query "DELETE FROM files WHERE id=".intval($id);
        unlink($row['path']);
        unlink($row['cover_photo']);
        $result mysqli_query($con,$query) or die ( mysqli_error()); 
        Admin though this code delete the mysql record original files are not deleting?? pls help me??

        Comment


          #5
          PHP Code:
          require('db.php');
          $id=$_REQUEST['id'];
          $query "SELECT * from files where id=".intval($id);
          unlink($row['path']);
          unlink($row['cover_photo']);
          $query "DELETE FROM files WHERE id=".intval($id);
          $result mysqli_query($con,$query) or die ( mysqli_error()); 
          this code is also not worked

          Comment


            #6
            PHP Code:
            require('db.php');
            $id=intval($_REQUEST['id']);
            $query "SELECT * from files where id=".$id;
            $result mysqli_query($con,$query) or die ( mysqli_error());
            /* associative array */
            $row mysqli_fetch_array($resultMYSQLI_ASSOC);
            unlink($row['path']);
            unlink($row['cover_photo']);
            $query "DELETE FROM files WHERE id=".$id;
            $result mysqli_query($con,$query) or die ( mysqli_error()); 
            Advertise your mobile site for FREE with AdTwirl

            Comment


              #7
              thank you GumSlone worked 100%

              Comment


                #8
                this thread is closed

                Comment

                Working...
                X