I was having a problem with the unlink() function but thanks to everyone on these forums, I realize it was actually an SQL problem. Here's the code:
Code: Select all
if (isset($_GET['photo_id']) && !$_POST) {
//prepare SQL query
$sql = 'SELECT photo_id, photo_name, file_name, thumb_name
FROM wallsanddoors WHERE photo_id = ?';
//initialize statement
$stmt = $conn->stmt_init();
if ($stmt->prepare($sql)) {
//bind the query parameters
$stmt->bind_param('i', $_GET['photo_id']);
//bind the results to variables
$stmt->bind_result($photo_id, $photo_name, $file_name, $thumb_name);
//execute the query and fetch the result
$OK = $stmt->execute();
$stmt->fetch();
}
}
// if confirm deletion button has been clicked, delete record
if (array_key_exists('delete', $_POST)) {
unlink(DELETE_DIR.$file_name);
unlink(THUMBS_DIR.$thumb_name);
$sql = 'DELETE FROM wallsanddoors WHERE photo_id = ?';
$stmt = $conn->stmt_init();
if ($stmt->prepare($sql)) {
$stmt->bind_param('i', $_POST['photo_id']);
$deleted = $stmt->execute();
}
}
Does anyone know how I can achieve this goal? I'm having a very hard time getting this to work. Thanks so much for your help!