Jump to content


Photo

Confirm Delete


  • Please log in to reply
5 replies to this topic

#1 mkklepper

mkklepper
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 26 October 2006 - 05:45 PM

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.

echo "<a href=\"del_music.php?trackname=".$trname."\">Delete Song</a>";

My delete page looks like this

<?

$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>

Every time I push yes, I get the error msg:
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


#2 php_joe

php_joe
  • Members
  • PipPipPip
  • Advanced Member
  • 175 posts

Posted 26 October 2006 - 05:49 PM

how about:

if(!unlink($delete_music)) echo "Delete of $delete_music failed";
if(!unlink($delete_mp3)) echo "Delete of $delete_mp3 failed";

Joe
[url=http://darkswordsguide.com][/url]

#3 mkklepper

mkklepper
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 26 October 2006 - 05:54 PM

The problem is that the variable $trackname is not making it into the file path for the unlink function.
(see the error msg)

#4 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 26 October 2006 - 06:00 PM

You need to pass the track name from the confrim page:

<?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>


Orio.
Think you're smarty?

(Gone until 20 to November)

#5 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 October 2006 - 06:08 PM

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

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#6 mkklepper

mkklepper
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 26 October 2006 - 07:09 PM

I guess I was a little too close to the project huh?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users