The following code starts deleting entries after a user presses the Delete button:
if (isset($_POST['action']) and $_POST['action'] == 'Delete')
{
try
{
$sql = 'SELECT id FROM joke WHERE authorid = :id';
$s = $pdo->prepare($sql);
$s->bindValue(':id', $_POST['id']);
$s->execute(); // -> means to call a method (a function stored in an object)
}
catch (PDOException $e)
{
$error = 'Error getting list of jokes to delete.';
include 'error.html.php';
exit();
}
How do I insert a way to momentarily prevent this code from executing to show a warning notice with an option to cancel, but continue the code if they choose that option? I’m confused because I can do it with JavaScript and HTML, but not this way.
It seems to me that I would insert a JavaScript function so that when the Delete button is clicked, a Confirm popop is seen. In the confirmation button, <?php code is inserted for the deletion page ?> So the deletion is not delayed, but started after the confirm. But then somehow the form contents has to carry through the JavaScript to the next page.