PHP Novice to Ninja - Chapter 7 "Confirm on Delete"

Hi Guys, I’ve been working my way through this book and up until this point its been pretty straight forward. There is an optional task to make the user confirm you want to delete the author in this chapter and I got stuck for the past hour trying to get it to work.

I’m wondering if someone can point out what I have done wrong here, everything works if I remove my extra code to confirm the action.

Index Page

if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
	include 'confirm.delete.php';
	exit();
}
if (isset($_POST['action']) and $_POST['action'] == 'Unconfirmed')
{
	include 'authors.html.php'
	exit();
}
if (isset($_POST['action']) and $_POST['action'] == 'Confirmed')
{	
	try
	{  ...code that deletes user is here

Confirm Delete HTML(confirm.delete.php)

<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/phpnin/includes/helpers.inc.php'; ?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Confirm Author Deletion</title>
	</head>
	<body>
		<h1>Manage Authors</h1>
		<p>Are you sure you want to delete author <?php htmlout($_POST['name']); ?>?</p>
				<form action=" " method="post">
					<div>
						<input type="hidden" name="id" value="<?php echo ($_POST['id']); ?>">
						<input type="submit" action="action" value="Confirmed">
						<input type="submit" action="action" value="Unconfirmed">
					</div>
				</form>
</body>
</html>

What error if any are you getting when you’re trying your code?

Have a read of the manual page about exceptions (just in case you’ve got the syntax wrong)

Thanks for the reply… I’m not getting an error, it simply seems like the if statements for “Confirm” and “Uncofirm” aren’t executing, it just returns to the main page. I tried getting them to echo some text but the only one that works is the “Delete” button which is included in the index.php file from another file called “authors.html.php” –

	<?php foreach ($authors as $author): ?>
			<li>
				<form action=" " method="post">
					<div>
						<?php htmlout($author['name']); ?>
						<input type="hidden" name="id" value="<?php echo ($author['id']); ?>">
						<input type="hidden" name="name" value="<?php echo ($author['name']); ?>">
						<br/>
						<input type="submit" name="action" value="Edit">
						<input type="submit" name="action" value="Delete">
					</div>
				</form>
			</li>
			<?php endforeach; ?>