Jump to content

Confirm Delete


mkklepper

Recommended Posts

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 12

Warning: 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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.