I ask for help with PHP code.
Simple unlink function works, but when it is in loop, it doesnt work. There has to be a problem somewhere. So heres the problem. I have a simple page where you can delete the navigation items. If user deletes navigation item (hes an administrator) and that link to page with some photos in it, I want to delete these photos when the user delete whole page.
The PHP code:
$sql2 = "SELECT * FROM foto WHERE ID=".$inid;
$vysledek = mysql_query($sql2) or die (mysql_error());
while ($zaznam= MySQL_Fetch_Array($vysledek)) {
$path = "maly/maly".$zaznam["url_v"];
unlink($path);
$path2 = "uploads/".$zaznam["url_v"];
unlink($path2);
}
This code wont delete all matched photos.
First the statement
Might be incorrect, perhaps
(ignoring the fact of potential SQL injection).
But,
Why not echo the values of the current working directory along with
$pathand$path2to find out what is going wrong?Otherwise it is difficult to tell.
BTW – mysql_* libraries are deprecated. Should move to summat like PDO or mysqli.