Jump to content

Archived

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

mkklepper

Confirm Delete

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
The problem is that the variable $trackname is not making it into the file path for the unlink function.
(see the error msg)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Why not just use a javascript confirmation on the link itself? It sure saves a [b]ton[/b] of backend coding:
[code]
<?php
echo "<a href=\"del_music.php?trackname=$trname\" onclick=\"return confirm('Are you sure?');\">Delete Song</a>";
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.