prepare('SELECT imagen_url FROM info_productos WHERE id = ?'); $stmt->execute([$id]); $imagen_url = $stmt->fetchColumn(); // Delete the record from the database $stmt = $pdo->prepare('DELETE FROM info_productos WHERE id = ?'); $stmt->execute([$id]); // If there was an image, delete the file if ($imagen_url && file_exists($imagen_url)) { unlink($imagen_url); } $_SESSION['success_message'] = 'La tarjeta de información ha sido eliminada con éxito.'; } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); $_SESSION['error_message'] = 'Error al eliminar la tarjeta. Por favor, contacta a soporte.'; } header('Location: info_producto.php'); exit; ?>