Hello forum,
I’m still new to PHP and I’m hoping someone can help me with a challenge that is mentioned on page 207 of Build Your Own Database Driven Web Site Using PHP and MySQL, the 4th Edition. I’m sure it’s quite easy, however I just can’t figure it out.
The challenge is to add a confirmation prompt via PHP. The book states that you “modify the controller to respond to the delete button by simply displaying another template, this one prompting the user to confirm the action. When the user submits the form in this page, it should trigger the code in the controller to actually delete the data.” The book also states that the “second form will also have to submit in a hidden field the ID of the author to be deleted.”
Here is start of the controller content page for deleting the author (index.php):
If (isset($_POST[‘action’]) and $_POST[‘action’] == ‘Delete’)
{
…delete code
}
header(‘Location: .’);
exit();
Here is body of the page that displays the list of authors (authors.php):
<body>
<h1>Manage Authors</h1>
<p><a href="?add">Add new author</a></p>
<ul>
<?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="submit" name="action" value="Edit"/>
<input type="submit" name="action" value="Delete"/>
</div>
</form>
</li>
<?php endforeach; ?>
</ul>
<p><a href="..">Return to JMS home</a></p>
</body>
I’m assuming that I need a third page that would be the confirmation page, like a confirm.php to prompt the user? Thank you again for reading my post and any help on how I would modify/create all three pages would be greatly appreciated. --Ben