PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This is driving me mad. I think it's a formatting error but I've been round in circles trying every combination I can think of. Basically, this section of my PHP interrogates a table in my dB and deletes all files listed under a particular code.
$query2 = "SELECT filename FROM photos WHERE code='$code'";
$result = mysql_query($query2)
or die (mysql_error());
// SET THE LOOP TO DELETE PHOTOGRAPHS
while($row = mysql_fetch_assoc($result))
{
$filename2 = $query2;
extract($row);
$myFile = "../photos/$filename2";
$fh = fopen($myfile,'w') or die ("Can't open file");
fclose($fh);
unlink($myFile);}
And this is the error I keep getting...
Warning: fopen() [function.fopen]: Filename cannot be empty in /home/beautyby/public_html/admin/price.php on line 41
Can't open file
$query2 = "SELECT filename FROM photos WHERE code='$code'";
$result = mysql_query($query2) or die (mysql_error());
// SET THE LOOP TO DELETE PHOTOGRAPHS
while($row = mysql_fetch_assoc($result))
{
$filename2 = $row['filename'];
$myFile = "../photos/$filename2";
$fh = fopen($myfile,'w') or die ("Can't open file");
fclose($fh);
unlink($myFile);
}
if ($delete == "yes")
{$query = "DELETE FROM prices WHERE code='$code'";
$result = mysql_query($query)
or die ("Couldn't execute query.");
$query2 = "SELECT filename FROM photos WHERE code='$code'";
$result = mysql_query($query2) or die (mysql_error());
// SET THE LOOP TO DELETE PHOTOGRAPHS
while($row = mysql_fetch_assoc($result))
{
$filename2 = $row['filename'];
$myFile = "../photos/$filename2";
$fh = fopen($myfile,'w') or die ("Can't open file");
fclose($fh);
unlink($myFile);
}
$query3 = "DELETE FROM photos WHERE code='$code'";
$result = mysql_query($query3)
or die ("Couldn't execute query.");
}
I get this...
Warning: fopen() [function.fopen]: Filename cannot be empty in /home/beautyby/public_html/admin/price.php on line 39
Can't open file