I am trying to delete a row off my db as well as a file. I can get the script to delete a row, but the file still remains.
In my db I have a field titled "file" this field stores just the name of the file.
The actual file is stored in a subdirectory called "media"
Now in my admin section I created a list all page (list.php) which allows admins to update or delete a row.
When the admin clicks on the "delete" hyperlink - the page calls for delete.php
The delete.php has this code:
<?php
session_start();
if(!session_is_registered(myusername)){
header("location:login.php");
}
include("includes/config.inc.php");
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar *This is from the list.php page
$id=$_GET['id'];
// Delete data in mysql from row that has this id
$sql="DELETE FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
// if successfully deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='list.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
// close connection
mysql_close();
?>
I know that I am to use the unlink command:
$file = "../media/['file']";
unlink($file);
But how do I Get the $file value to reflect the value from the field?