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

Started on the old forum in November 2020 · view the original in the archive · old links redirect here

7 replies · 112 views · started 6 years ago · 1 min read

2 participants
ayesham Developer · 69 posts #1

hello All,

 

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.

GumSlone Administrator Principal · 1,690 posts #2

hi, your code is insecure, use:

$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.

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

External image (may be gone)

ayesham Developer · 69 posts #3

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

ayesham Developer · 69 posts #4
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??

ayesham Developer · 69 posts #5
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

GumSlone Administrator Principal · 1,690 posts #6
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($result, MYSQLI_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

External image (may be gone)

ayesham Developer · 69 posts #7

🙂 thank you GumSlone worked 100%

ayesham Developer · 69 posts #8

this thread is closed8)😊

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close