Hello
Decided it would be wise to make use of the unlink function to remove files as well as database table rows. However, having a few headaches getting it to work. Here is the unlink code I am trying to use:
$file_path = "/home/domain/www/directory";
$delete = unlink($file_path/$filename);
And below is the php. I cannot figure out how to get the $filename to populate with the pic_name (which is the image name and includes the .jpg file extension).
<?php
require_once ('mysql_connect.php');
if (isset ($_POST['submit'])) {
$query = "DELETE FROM table WHERE pic_id={$_POST['id']} LIMIT 1";
$r = mysql_query ($query);
} else {
if (is_numeric ($_GET['pic_id']) ) {
$query = "SELECT pic_name, pic_id, pic_desc FROM table WHERE pic_id={$_GET['pic_id']}";
if ($r = mysql_query ($query)) {
$row = mysql_fetch_array ($r);
print '<form action="delete.php" method="post">
<p>are you sure you want to delete this entry?</p>
<p><img src="images/' . $row['pic_name'] . '" />
<br />' . $row['pic_desc'] . '<br />
<input type="hidden" name="id" value="' . $_GET['pic_id'] . '" />
<input type="submit" name="submit" value="delete entry" /></p>
</form>';
} else {
print "could not retreive entry";
}
}
}
?>
Many thanks