mkklepper Posted October 26, 2006 Share Posted October 26, 2006 I am creating a music page for a local musician. He can upload files himself but I'm having trouble setting up a confirmation page for when he deletes a song. I am sending the info via $_GET in a <a href="..."> tag.[code]echo "<a href=\"del_music.php?trackname=".$trname."\">Delete Song</a>";[/code]My delete page looks like this[code]<?$trackname = $_GET['trackname'];$dir2 = ('uploads/music/');$dir3 = ('uploads/mp3/');$delete_music = $dir2 . $trackname . ".txt";$delete_mp3 = $dir3 . $trackname . ".mp3";if(isset($_POST['yes'])){unlink($delete_music);unlink ($delete_mp3); if(!file_exists($delete_music)){ echo "<div id =\"box\" align=\"center\">The song \"".$trackname."\" has been deleted! <a href=\"manage_music.php\">Back</a></div>"; } }else{if(isset($_POST['no'])){header ('Location: manage_music.php');exit(); }}require ('templates/edit_head.html');?><div id="box" align="center"><p>Are you sure you want to delete: <?= $trackname ?> ?</p><form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"><input type="submit" name="yes" value="Yes" /><input type="submit" name="no" value="No" /></form></div>[/code]Every time I push yes, I get the error msg:[code]Warning: unlink(uploads/music/.txt) [function.unlink]: No such file or directory in C:\wamp\www\Apollo2\del_music.php on line 12Warning: unlink(uploads/mp3/.mp3) [function.unlink]: No such file or directory in C:\wamp\www\Apollo2\del_music.php on line 13[/code] Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/ Share on other sites More sharing options...
php_joe Posted October 26, 2006 Share Posted October 26, 2006 how about:[code]if(!unlink($delete_music)) echo "Delete of $delete_music failed";if(!unlink($delete_mp3)) echo "Delete of $delete_mp3 failed";[/code]Joe Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/#findComment-114939 Share on other sites More sharing options...
mkklepper Posted October 26, 2006 Author Share Posted October 26, 2006 The problem is that the variable $trackname is not making it into the file path for the unlink function.(see the error msg) Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/#findComment-114944 Share on other sites More sharing options...
Orio Posted October 26, 2006 Share Posted October 26, 2006 You need to pass the track name from the confrim page:[code]<?php$trackname = $_GET['trackname'];$dir2 = ('uploads/music/');$dir3 = ('uploads/mp3/');$delete_music = $dir2 . $trackname . ".txt";$delete_mp3 = $dir3 . $trackname . ".mp3";if(isset($_GET['yes'])){unlink($delete_music);unlink ($delete_mp3); if(!file_exists($delete_music)){ die "<div id =\"box\" align=\"center\">The song \"".$trackname."\" has been deleted! <a href=\"manage_music.php\">Back</a></div>"; } }else{if(isset($_GET['no'])){header ('Location: manage_music.php');exit(); }}require ('templates/edit_head.html');?><div id="box" align="center"><p>Are you sure you want to delete: <?= $trackname ?> ?</p><form action="<?= $_SERVER['PHP_SELF'] ?>" method="GET"><input type="hidden" name="trackname" value="<?php echo $_GET['trackname']; ?>"><input type="submit" name="yes" value="Yes" /><input type="submit" name="no" value="No" /></form></div>[/code]Orio. Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/#findComment-114951 Share on other sites More sharing options...
obsidian Posted October 26, 2006 Share Posted October 26, 2006 Why not just use a javascript confirmation on the link itself? It sure saves a [b]ton[/b] of backend coding:[code]<?phpecho "<a href=\"del_music.php?trackname=$trname\" onclick=\"return confirm('Are you sure?');\">Delete Song</a>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/#findComment-114961 Share on other sites More sharing options...
mkklepper Posted October 26, 2006 Author Share Posted October 26, 2006 I guess I was a little too close to the project huh? Link to comment https://forums.phpfreaks.com/topic/25211-confirm-delete/#findComment-115011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.